From 63a5c76cbe83b54e4cb3b976b4bc84289d0ac4b3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 2 Mar 2020 16:11:34 +0000 Subject: [PATCH] Sending dms to onion domains --- daemon.py | 14 +++++++++----- epicyon.py | 1 + outbox.py | 6 ++++-- posts.py | 17 ++++++++++++++--- schedule.py | 1 + utils.py | 1 + 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/daemon.py b/daemon.py index 32c11677c..fa8c0d5b9 100644 --- a/daemon.py +++ b/daemon.py @@ -684,7 +684,8 @@ class PubServer(BaseHTTPRequestHandler): self.postToNickname=postToNickname return postMessageToOutbox(messageJson,self.postToNickname, \ self.server,self.server.baseDir,self.server.httpPrefix, \ - self.server.domain,self.server.domainFull,self.server.port, \ + self.server.domain,self.server.domainFull, \ + self.server.onionDomain,self.server.port, \ self.server.recentPostsCache,self.server.followersThreads, \ self.server.federationList,self.server.sendThreads, \ self.server.postLog,self.server.cachedWebfingers, \ @@ -3521,8 +3522,10 @@ class PubServer(BaseHTTPRequestHandler): if pageNumberStr.isdigit(): pageNumber=int(pageNumberStr) searchPath=self.path.split('?page=')[0] - getPerson = personLookup(self.server.domain,searchPath.replace('/following',''), \ - self.server.baseDir) + getPerson = \ + personLookup(self.server.domain, \ + searchPath.replace('/following',''), \ + self.server.baseDir) if getPerson: if not self.server.session: if self.server.debug: @@ -3623,8 +3626,9 @@ class PubServer(BaseHTTPRequestHandler): self._benchmarkGETtimings(GETstartTime,GETtimings,52) # look up a person - getPerson = personLookup(self.server.domain,self.path, \ - self.server.baseDir) + getPerson = \ + personLookup(self.server.domain,self.path, \ + self.server.baseDir) if getPerson: if self._requestHTTP(): if not self.server.session: diff --git a/epicyon.py b/epicyon.py index 177974c5c..10a65c46a 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1005,6 +1005,7 @@ if args.actor: asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} if '/channel/' in personUrl: asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} + personJson = getJson(session,personUrl,asHeader,None,__version__,httpPrefix,None) if personJson: pprint(personJson) diff --git a/outbox.py b/outbox.py index 4086997cc..4ca6b3af7 100644 --- a/outbox.py +++ b/outbox.py @@ -38,7 +38,8 @@ from shares import outboxUndoShareUpload def postMessageToOutbox(messageJson: {},postToNickname: str, \ server,baseDir: str,httpPrefix: str, \ - domain: str,domainFull: str,port: int, \ + domain: str,domainFull: str,onionDomain: str, \ + port: int, \ recentPostsCache: {},followersThreads: [], \ federationList: [],sendThreads: [], \ postLog: [],cachedWebfingers: {}, \ @@ -313,7 +314,8 @@ def postMessageToOutbox(messageJson: {},postToNickname: str, \ else: print('c2s sender: '+postToNickname+'@'+domain+':'+str(port)) sendToNamedAddresses(server.session,baseDir, \ - postToNickname,domain,port, \ + postToNickname, \ + domain,onionDomain,port, \ httpPrefix, \ federationList, \ sendThreads, \ diff --git a/posts.py b/posts.py index 45a6a2bfd..63af3b60b 100644 --- a/posts.py +++ b/posts.py @@ -1704,7 +1704,8 @@ def addToField(activityType: str,postJsonObject: {},debug: bool) -> ({},bool): return postJsonObject,False def sendToNamedAddresses(session,baseDir: str, \ - nickname: str, domain: str, port: int, \ + nickname: str, \ + domain: str,onionDomain: str,port: int, \ httpPrefix: str,federationList: [], \ sendThreads: [],postLog: [], \ cachedWebfingers: {},personCache: {}, \ @@ -1810,11 +1811,21 @@ def sendToNamedAddresses(session,baseDir: str, \ toDomainFull=toDomain+':'+str(toPort) print('DEBUG: Post sending s2s: '+nickname+'@'+domainFull+ \ ' to '+toNickname+'@'+toDomainFull) + + # if we have an alt onion domain and we are sending to + # another onion domain then switch the clearnet + # domain for the onion one + fromDomain=domain + fromHttpPrefix=httpPrefix + if onionDomain: + if toDomain.endswith('.onion'): + fromDomain=onionDomain + fromHttpPrefix='http' cc=[] sendSignedJson(postJsonObject,session,baseDir, \ - nickname,domain,port, \ + nickname,fromDomain,port, \ toNickname,toDomain,toPort, \ - cc,httpPrefix,True,clientToServer, \ + cc,fromHttpPrefix,True,clientToServer, \ federationList, \ sendThreads,postLog,cachedWebfingers, \ personCache,debug,projectVersion) diff --git a/schedule.py b/schedule.py index 00ba864b3..0345358b7 100644 --- a/schedule.py +++ b/schedule.py @@ -87,6 +87,7 @@ def updatePostSchedule(baseDir: str,handle: str,httpd,maxScheduledPosts: int) -> httpd.httpPrefix, \ httpd.domain, \ httpd.domainFull, \ + httpd.onionDomain, \ httpd.port, \ httpd.recentPostsCache, \ httpd.followersThreads, \ diff --git a/utils.py b/utils.py index ac24d21e2..9e573b1d8 100644 --- a/utils.py +++ b/utils.py @@ -68,6 +68,7 @@ def loadJsonOnionify(filename: str,domain: str,onionDomain: str,delaySec=2) -> { data=fp.read() if data: data=data.replace(domain,onionDomain).replace('https:','http:') + print('*****data: '+data) jsonObject=json.loads(data) break except: