From 0fb0f894624cccf8309afa7155203838e9cace2d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 2 Aug 2019 13:49:34 +0100 Subject: [PATCH] Add an instance identifier --- daemon.py | 6 +++++- epicyon.py | 10 +++++++++- tests.py | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/daemon.py b/daemon.py index 6d1f21ac..9d3a0436 100644 --- a/daemon.py +++ b/daemon.py @@ -123,6 +123,7 @@ class PubServer(BaseHTTPRequestHandler): if cookie: self.send_header('Cookie', cookie) self.send_header('Host', self.server.domainFull) + self.send_header('InstanceID', self.server.instanceId) self.end_headers() def _redirect_headers(self,redirect: str,cookie: str) -> None: @@ -132,6 +133,7 @@ class PubServer(BaseHTTPRequestHandler): self.send_header('Cookie', cookie) self.send_header('Location', redirect) self.send_header('Host', self.server.domainFull) + self.send_header('InstanceID', self.server.instanceId) self.end_headers() def _404(self) -> None: @@ -2101,7 +2103,8 @@ class PubServer(BaseHTTPRequestHandler): self.end_headers() self.server.POSTbusy=False -def runDaemon(clientToServer: bool,baseDir: str,domain: str, \ +def runDaemon(instanceId,clientToServer: bool, \ + baseDir: str,domain: str, \ port=80,httpPrefix='https', \ fedList=[],noreply=False,nolike=False,nopics=False, \ noannounce=False,cw=False,ocapAlways=False, \ @@ -2128,6 +2131,7 @@ def runDaemon(clientToServer: bool,baseDir: str,domain: str, \ httpd.debug=debug httpd.federationList=fedList.copy() httpd.baseDir=baseDir + httpd.instanceId=instanceId httpd.personCache={} httpd.cachedWebfingers={} httpd.useTor=useTor diff --git a/epicyon.py b/epicyon.py index 570f34e1..bc793d02 100644 --- a/epicyon.py +++ b/epicyon.py @@ -310,6 +310,13 @@ if args.domain: domain=args.domain setConfigParam(baseDir,'domain',domain) +# unique ID for the instance +instanceId=getConfigParam(baseDir,'instanceId') +if not instanceId: + instanceId=createPassword(32) + setConfigParam(baseDir,'instanceId',instanceId) + print('Instance ID: '+instanceId) + # get domain name from configuration configDomain=getConfigParam(baseDir,'domain') if configDomain: @@ -1196,7 +1203,8 @@ if args.testdata: followerOfPerson(baseDir,nickname,domain,'drokk',domainFull,federationList,False) followerOfPerson(baseDir,nickname,domain,'maxboardroom',domainFull,federationList,False) -runDaemon(args.client,baseDir,domain,port,httpPrefix, \ +runDaemon(instanceId,args.client,baseDir, \ + domain,port,httpPrefix, \ federationList, \ args.noreply,args.nolike,args.nopics, \ args.noannounce,args.cw,ocapAlways, \ diff --git a/tests.py b/tests.py index 91384e5d..6591c6d4 100644 --- a/tests.py +++ b/tests.py @@ -181,7 +181,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \ global testServerAliceRunning testServerAliceRunning = True print('Server running: Alice') - runDaemon(False,path,domain,port,httpPrefix,federationList, \ + runDaemon("instanceId",False,path,domain,port,httpPrefix,federationList, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ useTor,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ @@ -233,7 +233,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \ global testServerBobRunning testServerBobRunning = True print('Server running: Bob') - runDaemon(False,path,domain,port,httpPrefix,federationList, \ + runDaemon("instanceId",False,path,domain,port,httpPrefix,federationList, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ useTor,maxReplies, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \ @@ -265,7 +265,7 @@ def createServerEve(path: str,domain: str,port: int,federationList: [], \ global testServerEveRunning testServerEveRunning = True print('Server running: Eve') - runDaemon(False,path,domain,port,httpPrefix,federationList, \ + runDaemon("instanceId",False,path,domain,port,httpPrefix,federationList, \ noreply,nolike,nopics,noannounce,cw,ocapAlways, \ useTor,maxReplies,allowDeletion,True)