Port numbers after domain

master
Bob Mottram 2019-06-30 20:01:43 +01:00
parent 6c85b39adc
commit 78a3e96434
5 changed files with 26 additions and 11 deletions

View File

@ -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:

View File

@ -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()

View File

@ -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',

View File

@ -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:

View File

@ -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: