forked from indymedia/epicyon
Tidying
parent
73a2b37696
commit
553a6f25c1
85
daemon.py
85
daemon.py
|
@ -785,36 +785,15 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.outboxThread[accountOutboxThreadName].start()
|
self.server.outboxThread[accountOutboxThreadName].start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _inboxQueueCleardown(self) -> None:
|
|
||||||
""" Check if the queue is full and remove oldest items if it is
|
|
||||||
"""
|
|
||||||
if len(self.server.inboxQueue) < self.server.maxQueueLength:
|
|
||||||
return
|
|
||||||
print('Inbox queue is full (' + str(self.server.maxQueueLength) +
|
|
||||||
' items). Removing oldest items.')
|
|
||||||
cleardownStartTime = time.time()
|
|
||||||
removals = 0
|
|
||||||
while len(self.server.inboxQueue) >= self.server.maxQueueLength / 2:
|
|
||||||
queueFilename = self.server.inboxQueue[0]
|
|
||||||
if os.path.isfile(queueFilename):
|
|
||||||
try:
|
|
||||||
os.remove(queueFilename)
|
|
||||||
removals += 1
|
|
||||||
except BaseException:
|
|
||||||
print('WARN: unable to remove inbox queue file ' +
|
|
||||||
queueFilename)
|
|
||||||
pass
|
|
||||||
self.server.inboxQueue.pop(0)
|
|
||||||
timeDiff = str(int((time.time() - cleardownStartTime) * 1000))
|
|
||||||
print('Inbox cleardown took ' + timeDiff + ' mS. Removed ' +
|
|
||||||
str(removals) + ' items. Queue length is now ' +
|
|
||||||
str(len(self.server.inboxQueue)))
|
|
||||||
|
|
||||||
def _updateInboxQueue(self, nickname: str, messageJson: {},
|
def _updateInboxQueue(self, nickname: str, messageJson: {},
|
||||||
messageBytes: str) -> int:
|
messageBytes: str) -> int:
|
||||||
"""Update the inbox queue
|
"""Update the inbox queue
|
||||||
"""
|
"""
|
||||||
self._inboxQueueCleardown()
|
# if the inbox queue is full then return a busy code
|
||||||
|
if len(self.server.inboxQueue) >= self.server.maxQueueLength:
|
||||||
|
self._503()
|
||||||
|
self.server.POSTbusy = False
|
||||||
|
return 2
|
||||||
|
|
||||||
# Convert the headers needed for signature verification to dict
|
# Convert the headers needed for signature verification to dict
|
||||||
headersDict = {}
|
headersDict = {}
|
||||||
|
@ -866,8 +845,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return 0
|
return 0
|
||||||
self.send_response(503)
|
self._503()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -1016,19 +994,6 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._400()
|
self._400()
|
||||||
return
|
return
|
||||||
|
|
||||||
# if self.server.blocklistUpdateCtr<=0:
|
|
||||||
# self.server.blocklistUpdateCtr = \
|
|
||||||
# self.server.blocklistUpdateInterval
|
|
||||||
# self.server.domainBlocklist = \
|
|
||||||
# getDomainBlocklist(self.server.baseDir)
|
|
||||||
|
|
||||||
# self.server.blocklistUpdateCtr-=1
|
|
||||||
|
|
||||||
# if callingDomain in self.server.domainBlocklist:
|
|
||||||
# print('GET domain blocked: '+callingDomain)
|
|
||||||
# self._400()
|
|
||||||
# return
|
|
||||||
|
|
||||||
GETstartTime = time.time()
|
GETstartTime = time.time()
|
||||||
GETtimings = []
|
GETtimings = []
|
||||||
|
|
||||||
|
@ -4350,6 +4315,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('WARN: Unauthenticated GET')
|
print('WARN: Unauthenticated GET')
|
||||||
self._404()
|
self._404()
|
||||||
|
self.server.GETbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
self._benchmarkGETtimings(GETstartTime, GETtimings, 54)
|
self._benchmarkGETtimings(GETstartTime, GETtimings, 54)
|
||||||
|
@ -5027,22 +4993,10 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self._400()
|
self._400()
|
||||||
return
|
return
|
||||||
|
|
||||||
# if self.server.blocklistUpdateCtr<=0:
|
|
||||||
# self.server.blocklistUpdateCtr=self.server.blocklistUpdateInterval
|
|
||||||
# self.server.domainBlocklist=getDomainBlocklist(self.server.baseDir)
|
|
||||||
|
|
||||||
# self.server.blocklistUpdateCtr-=1
|
|
||||||
|
|
||||||
# if callingDomain in self.server.domainBlocklist:
|
|
||||||
# print('POST domain blocked: '+callingDomain)
|
|
||||||
# self._400()
|
|
||||||
# return
|
|
||||||
|
|
||||||
self.server.POSTbusy = True
|
self.server.POSTbusy = True
|
||||||
if not self.headers.get('Content-type'):
|
if not self.headers.get('Content-type'):
|
||||||
print('Content-type header missing')
|
print('Content-type header missing')
|
||||||
self.send_response(400)
|
self._400()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -5057,6 +5011,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if self.path == '/inbox':
|
if self.path == '/inbox':
|
||||||
if not self.server.enableSharedInbox:
|
if not self.server.enableSharedInbox:
|
||||||
self._503()
|
self._503()
|
||||||
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
cookie = None
|
cookie = None
|
||||||
|
@ -6769,8 +6724,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.path.endswith('/caps/new') or
|
self.path.endswith('/caps/new') or
|
||||||
self.path == '/sharedInbox'):
|
self.path == '/sharedInbox'):
|
||||||
print('Attempt to POST to invalid path ' + self.path)
|
print('Attempt to POST to invalid path ' + self.path)
|
||||||
self.send_response(400)
|
self._400()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -6785,15 +6739,13 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
not self.headers['Content-type'].startswith('audio/'):
|
not self.headers['Content-type'].startswith('audio/'):
|
||||||
if length > self.server.maxMessageLength:
|
if length > self.server.maxMessageLength:
|
||||||
print('Maximum message length exceeded ' + str(length))
|
print('Maximum message length exceeded ' + str(length))
|
||||||
self.send_response(400)
|
self._400()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if length > self.server.maxMediaSize:
|
if length > self.server.maxMediaSize:
|
||||||
print('Maximum media size exceeded ' + str(length))
|
print('Maximum media size exceeded ' + str(length))
|
||||||
self.send_response(400)
|
self._400()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -6810,8 +6762,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
pathUsersSection = self.path.split('/users/')[1]
|
pathUsersSection = self.path.split('/users/')[1]
|
||||||
if '/' not in pathUsersSection:
|
if '/' not in pathUsersSection:
|
||||||
self.send_response(404)
|
self._404()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
self.postFromNickname = pathUsersSection.split('/')[0]
|
self.postFromNickname = pathUsersSection.split('/')[0]
|
||||||
|
@ -6819,8 +6770,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.baseDir + '/accounts/' + \
|
self.server.baseDir + '/accounts/' + \
|
||||||
self.postFromNickname + '@' + self.server.domain
|
self.postFromNickname + '@' + self.server.domain
|
||||||
if not os.path.isdir(accountsDir):
|
if not os.path.isdir(accountsDir):
|
||||||
self.send_response(404)
|
self._404()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
mediaBytes = self.rfile.read(length)
|
mediaBytes = self.rfile.read(length)
|
||||||
|
@ -6851,8 +6801,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if length < self.server.maxPostLength:
|
if length < self.server.maxPostLength:
|
||||||
unknownPost = self.rfile.read(length).decode('utf-8')
|
unknownPost = self.rfile.read(length).decode('utf-8')
|
||||||
print(str(unknownPost))
|
print(str(unknownPost))
|
||||||
self.send_response(400)
|
self._400()
|
||||||
self.end_headers()
|
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -6970,7 +6919,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
queueStatus = \
|
queueStatus = \
|
||||||
self._updateInboxQueue(self.postToNickname,
|
self._updateInboxQueue(self.postToNickname,
|
||||||
messageJson, messageBytes)
|
messageJson, messageBytes)
|
||||||
if queueStatus == 0 or queueStatus == 1:
|
if queueStatus >= 0 and queueStatus <= 2:
|
||||||
return
|
return
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('_updateInboxQueue exited ' +
|
print('_updateInboxQueue exited ' +
|
||||||
|
@ -6987,7 +6936,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
print('DEBUG: POST to shared inbox')
|
print('DEBUG: POST to shared inbox')
|
||||||
queueStatus = \
|
queueStatus = \
|
||||||
self._updateInboxQueue('inbox', messageJson, messageBytes)
|
self._updateInboxQueue('inbox', messageJson, messageBytes)
|
||||||
if queueStatus == 0 or queueStatus == 1:
|
if queueStatus >= 0 and queueStatus <= 2:
|
||||||
return
|
return
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
|
|
Loading…
Reference in New Issue