From a55165c92286dba39bbfe1d7f0f04e3a712908bb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 15 Jul 2019 19:20:52 +0100 Subject: [PATCH] c2s sending to named addresses --- daemon.py | 36 +++++++++++++++++++++++++----------- posts.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 14 deletions(-) diff --git a/daemon.py b/daemon.py index cbead8a2..1fa4dcbe 100644 --- a/daemon.py +++ b/daemon.py @@ -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: diff --git a/posts.py b/posts.py index 32030db3..77b71f86 100644 --- a/posts.py +++ b/posts.py @@ -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