From 78a3e96434dd866caaa19f9d6d017f3f5c2023b9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 30 Jun 2019 20:01:43 +0100 Subject: [PATCH] Port numbers after domain --- daemon.py | 15 +++++++++++---- epicyon.py | 6 +++--- follow.py | 5 ++++- person.py | 4 ++-- posts.py | 7 ++++++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/daemon.py b/daemon.py index 36b77cdc..e32f1476 100644 --- a/daemon.py +++ b/daemon.py @@ -43,6 +43,9 @@ followsPerPage=12 # Whether to use https useHttps=True +# port number to use +usePort=80 + def readFollowList(filename: str): """Returns a list of ActivityPub addresses to follow """ @@ -114,19 +117,19 @@ class PubServer(BaseHTTPRequestHandler): self.GETbusy=False return # get outbox feed for a person - outboxFeed=personOutboxJson(thisDomain,self.path,useHttps,maxPostsInFeed) + outboxFeed=personOutboxJson(thisDomain,usePort,self.path,useHttps,maxPostsInFeed) if outboxFeed: self._set_headers('application/json') self.wfile.write(json.dumps(outboxFeed).encode('utf-8')) self.GETbusy=False return - following=getFollowingFeed(thisDomain,self.path,useHttps,followsPerPage) + following=getFollowingFeed(thisDomain,usePort,self.path,useHttps,followsPerPage) if following: self._set_headers('application/json') self.wfile.write(json.dumps(following).encode('utf-8')) self.GETbusy=False return - followers=getFollowingFeed(thisDomain,self.path,useHttps,followsPerPage,'followers') + followers=getFollowingFeed(thisDomain,usePort,self.path,useHttps,followsPerPage,'followers') if followers: self._set_headers('application/json') self.wfile.write(json.dumps(followers).encode('utf-8')) @@ -205,10 +208,14 @@ class PubServer(BaseHTTPRequestHandler): self.wfile.write(json.dumps(message).encode('utf-8')) self.POSTbusy=False -def runDaemon(domain: str,port=80,fedList=[],useTor=False) -> None: +def runDaemon(domain: str,port=80,https=True,fedList=[],useTor=False) -> None: global thisDomain global federationList + global usePort + global useHttps thisDomain=domain + usePort=port + useHttps=https federationList=fedList.copy() if len(domain)==0: diff --git a/epicyon.py b/epicyon.py index 223e5339..47039885 100644 --- a/epicyon.py +++ b/epicyon.py @@ -37,7 +37,7 @@ username='testuser' #domain=socket.gethostname() domain='127.0.0.1' port=6227 -https=True +https=False useTor=False session = createSession(useTor) @@ -72,10 +72,10 @@ setPreferredUsername(username,domain,'badger') setBio(username,domain,'Some personal info') #createPublicPost(username, domain, https, "G'day world!", False, True, None, None, 'Not suitable for Vogons') #archivePosts(username,domain,4) -#outboxJson=createOutbox(username,domain,https,2,True,None) +#outboxJson=createOutbox(username,domain,port,https,2,True,None) #pprint(outboxJson) -runDaemon(domain,port,federationList,useTor) +runDaemon(domain,port,https,federationList,useTor) #testHttpsig() #sys.exit() diff --git a/follow.py b/follow.py index 4c49185d..89a81a64 100644 --- a/follow.py +++ b/follow.py @@ -102,7 +102,7 @@ def getNoOfFollowers(username: str,domain: str) -> int: """ return getNoOfFollows(username,domain,'followers.txt') -def getFollowingFeed(domain: str,path: str,https: bool,followsPerPage=12,followFile='following') -> {}: +def getFollowingFeed(domain: str,port: int,path: str,https: bool,followsPerPage=12,followFile='following') -> {}: """Returns the following and followers feeds from GET requests """ if '/'+followFile not in path: @@ -138,6 +138,9 @@ def getFollowingFeed(domain: str,path: str,https: bool,followsPerPage=12,followF if not https: prefix='http' + if port!=80 and port!=443: + domain=domain+':'+str(port) + if headerOnly: following = { '@context': 'https://www.w3.org/ns/activitystreams', diff --git a/person.py b/person.py index 9c4e3a60..d3a9ed8e 100644 --- a/person.py +++ b/person.py @@ -163,7 +163,7 @@ def personLookup(domain: str,path: str) -> {}: personJson=commentjson.load(fp) return personJson -def personOutboxJson(domain: str,path: str,https: bool,noOfItems: int) -> []: +def personOutboxJson(domain: str,port: int,path: str,https: bool,noOfItems: int) -> []: """Obtain the outbox feed for the given person """ if not '/outbox' in path: @@ -197,7 +197,7 @@ def personOutboxJson(domain: str,path: str,https: bool,noOfItems: int) -> []: return None if not validUsername(username): return None - return createOutbox(username,domain,https,noOfItems,headerOnly,pageNumber) + return createOutbox(username,domain,port,https,noOfItems,headerOnly,pageNumber) def setPreferredUsername(username: str, domain: str, preferredName: str) -> bool: if len(preferredName)>32: diff --git a/posts.py b/posts.py index e9552e13..3adc093e 100644 --- a/posts.py +++ b/posts.py @@ -383,13 +383,18 @@ def sendPost(session,username: str, domain: str, toUsername: str, toDomain: str, thr.start() return 0 -def createOutbox(username: str,domain: str,https: bool,itemsPerPage: int,headerOnly: bool,pageNumber=None) -> {}: +def createOutbox(username: str,domain: str,port: int,https: bool,itemsPerPage: int,headerOnly: bool,pageNumber=None) -> {}: """Constructs the outbox feed """ prefix='https' if not https: prefix='http' + outboxDir = createOutboxDir(username,domain) + + if port!=80 and port!=443: + domain = domain+':'+str(port) + pageStr='?page=true' if pageNumber: try: