c2s sending to named addresses

master
Bob Mottram 2019-07-15 19:20:52 +01:00
parent c6a93e624d
commit a55165c922
2 changed files with 76 additions and 14 deletions

View File

@ -23,6 +23,7 @@ from posts import outboxMessageCreateWrap
from posts import savePostToBox
from posts import sendToFollowers
from posts import postIsAddressedToPublic
from posts import sendToNamedAddresses
from inbox import inboxPermittedMessage
from inbox import inboxMessageHasParams
from inbox import runInboxQueue
@ -149,20 +150,33 @@ class PubServer(BaseHTTPRequestHandler):
postId=messageJson['id']
else:
postId=None
if postIsAddressedToPublic(self.server.baseDir, \
messageJson):
if self.server.debug:
print('DEBUG: saving c2s post to outbox')
savePostToBox(self.server.baseDir,postId, \
self.postToNickname, \
self.server.domain,messageJson,'outbox')
savePostToBox(self.server.baseDir,postId, \
self.postToNickname, \
self.server.domain,messageJson,'outbox')
if self.server.debug:
print('DEBUG: sending c2s post to followers')
sendToFollowers(self.server.session,self.server.baseDir, \
self.postToNickname,self.server.domain, \
self.server.port,self.server.httpPrefix,
messageJson)
# TODO send to individual named addresses
self.postToNickname,self.server.domain, \
self.server.port, \
self.server.httpPrefix, \
self.server.federationList, \
self.server.sendThreads, \
self.server.postLog, \
self.server.cachedWebfingers, \
self.server.personCache, \
messageJson,self.server.debug)
if self.server.debug:
print('DEBUG: sending c2s post to named addresses')
sendToNamedAddresses(self.server.session,self.server.baseDir, \
self.postToNickname,self.server.domain, \
self.server.port, \
self.server.httpPrefix, \
self.server.federationList, \
self.server.sendThreads, \
self.server.postLog, \
self.server.cachedWebfingers, \
self.server.personCache, \
messageJson,self.server.debug)
return True
def _updateInboxQueue(self,nickname: str,messageJson: {}) -> int:

View File

@ -765,9 +765,55 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
thr.start()
return 0
def sendToFollowers(session,baseDir: str,
nickname: str, domain: str, port: int,httpPrefix: str,
postJsonObject: {}):
def sendToNamedAddresses(session,baseDir: str, \
nickname: str, domain: str, port: int, \
httpPrefix: str,federationList: [], \
sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \
postJsonObject: {},debug: bool) -> None:
"""sends a post to the specific named addresses in to/cc
"""
if port!=80 and port!=443:
domain=domain+':'+str(port)
if not postJsonObject.get('object'):
return False
if not postJsonObject['object'].get('to'):
return False
recipients=[]
recipientType=['to','cc']
for rType in recipientType:
for address in postJsonObject['object'][rType]:
if address.endswith('#Public'):
continue
if address.endswith('/followers'):
continue
recipients.append(address)
if not recipients:
return
clientToServer=False
for address in recipients:
toNickname=getNicknameFromActor(address)
if not toNickname:
continue
toDomain,toPort=getDomainFromActor(address)
if not toDomain:
continue
sendSignedJson(postJsonObject,session,baseDir, \
nickname,domain,port, \
toNickname,toDomain,toPort, \
cc,httpPrefix,True,clientToServer, \
federationList, \
sendThreads,postLog,cachedWebfingers, \
personCache,debug)
def sendToFollowers(session,baseDir: str, \
nickname: str, domain: str, port: int, \
httpPrefix: str,federationList: [], \
sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \
postJsonObject: {},debug: bool) -> None:
"""sends a post to the followers of the given nickname
"""
if not postIsAddressedToFollowers(baseDir,nickname,domain, \
@ -778,6 +824,8 @@ def sendToFollowers(session,baseDir: str,
if not grouped:
return
clientToServer=False
# for each instance
for followerDomain,followerHandles in grouped.items():
toPort=port