Threaded sending to named addresses

main
Bob Mottram 2021-10-20 21:00:09 +01:00
parent d43715ab07
commit 50796afb3c
3 changed files with 68 additions and 26 deletions

View File

@ -15,7 +15,7 @@ from posts import isImageMedia
from posts import outboxMessageCreateWrap
from posts import savePostToBox
from posts import sendToFollowersThread
from posts import sendToNamedAddresses
from posts import sendToNamedAddressesThread
from utils import hasObjectStringType
from utils import getBaseContentFromPost
from utils import hasObjectDict
@ -627,7 +627,8 @@ def postMessageToOutbox(session, translate: {},
else:
print('c2s sender: ' +
postToNickname + '@' + domain + ':' + str(port))
sendToNamedAddresses(server.session, baseDir,
namedAddressesThread = \
sendToNamedAddressesThread(server.session, baseDir,
postToNickname,
domain, onionDomain, i2pDomain, port,
httpPrefix,
@ -641,4 +642,5 @@ def postMessageToOutbox(session, translate: {},
sharedItemsFederatedDomains,
sharedItemFederationTokens,
signingPrivateKeyPem)
followersThreads.append(namedAddressesThread)
return True

View File

@ -2734,7 +2734,7 @@ def _isProfileUpdate(postJsonObject: {}) -> bool:
return False
def sendToNamedAddresses(session, baseDir: str,
def _sendToNamedAddresses(session, baseDir: str,
nickname: str, domain: str,
onionDomain: str, i2pDomain: str, port: int,
httpPrefix: str, federationList: [],
@ -2885,6 +2885,45 @@ def sendToNamedAddresses(session, baseDir: str,
signingPrivateKeyPem, 34436782)
def sendToNamedAddressesThread(session, baseDir: str,
nickname: str, domain: str,
onionDomain: str, i2pDomain: str, port: int,
httpPrefix: str, federationList: [],
sendThreads: [], postLog: [],
cachedWebfingers: {}, personCache: {},
postJsonObject: {}, debug: bool,
projectVersion: str,
sharedItemsFederatedDomains: [],
sharedItemFederationTokens: {},
signingPrivateKeyPem: str):
"""Returns a thread used to send a post to named addresses
"""
sendThread = \
threadWithTrace(target=_sendToNamedAddresses,
args=(session, baseDir,
nickname, domain,
onionDomain, i2pDomain, port,
httpPrefix, federationList,
sendThreads, postLog,
cachedWebfingers, personCache,
postJsonObject, debug,
projectVersion,
sharedItemsFederatedDomains,
sharedItemFederationTokens,
signingPrivateKeyPem), daemon=True)
try:
sendThread.start()
except SocketError as e:
print('WARN: socket error while starting ' +
'thread to send to named addresses. ' + str(e))
return None
except ValueError as e:
print('WARN: error while starting ' +
'thread to send to named addresses. ' + str(e))
return None
return sendThread
def _hasSharedInbox(session, httpPrefix: str, domain: str,
debug: bool, signingPrivateKeyPem: str) -> bool:
"""Returns true if the given domain has a shared inbox

View File

@ -4507,6 +4507,7 @@ def _testFunctions():
'do_POST',
'do_HEAD',
'__run',
'_sendToNamedAddresses',
'globaltrace',
'localtrace',
'kill',