Fix opposite addresses

main
Bob Mottram 2020-02-19 13:16:38 +00:00
parent 7e8d59e85c
commit 55dcdd546d
3 changed files with 44 additions and 43 deletions

View File

@ -147,7 +147,6 @@ from shares import outboxUndoShareUpload
from shares import addShare from shares import addShare
from shares import removeShare from shares import removeShare
from shares import expireShares from shares import expireShares
from utils import isPortInUse
from utils import removeAvatarFromCache from utils import removeAvatarFromCache
from utils import locatePost from utils import locatePost
from utils import getCachedPostFilename from utils import getCachedPostFilename
@ -5483,13 +5482,13 @@ def runDaemon(mediaInstance: bool,maxRecentPosts: int, \
else: else:
pubHandler = partial(PubServer) pubHandler = partial(PubServer)
if isPortInUse(proxyPort):
print('Process is already running on port '+str(proxyPort))
return False
try: try:
httpd = ThreadingHTTPServer(serverAddress, pubHandler) httpd = ThreadingHTTPServer(serverAddress, pubHandler)
except Exception as e: except Exception as e:
if e.errno==98:
print('ERROR: HTTP Server address is already in use. '+str(serverAddress))
return False
print('ERROR: HTTP Server failed to start. '+str(e)) print('ERROR: HTTP Server failed to start. '+str(e))
return False return False

View File

@ -189,7 +189,7 @@ def testThreads():
thr.join() thr.join()
assert thr.isAlive()==False assert thr.isAlive()==False
def createServerAlice(path: str,domain: str,port: int,federationList: [], \ def createServerAlice(path: str,domain: str,port: int,bobAddress: str,federationList: [], \
hasFollows: bool,hasPosts :bool,ocapAlways: bool,sendThreads: []): hasFollows: bool,hasPosts :bool,ocapAlways: bool,sendThreads: []):
print('Creating test server: Alice on port '+str(port)) print('Creating test server: Alice on port '+str(port))
if os.path.isdir(path): if os.path.isdir(path):
@ -217,9 +217,9 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
assert setSkillLevel(path,nickname,domain,'hacking',90) assert setSkillLevel(path,nickname,domain,'hacking',90)
assert setRole(path,nickname,domain,'someproject','guru') assert setRole(path,nickname,domain,'someproject','guru')
if hasFollows: if hasFollows:
followPerson(path,nickname,domain,'bob','127.0.0.100:61936', \ followPerson(path,nickname,domain,'bob',bobAddress, \
federationList,False) federationList,False)
followerOfPerson(path,nickname,domain,'bob','127.0.0.100:61936', \ followerOfPerson(path,nickname,domain,'bob',bobAddress, \
federationList,False) federationList,False)
if hasPosts: if hasPosts:
createPublicPost(path,nickname, domain, port,httpPrefix, \ createPublicPost(path,nickname, domain, port,httpPrefix, \
@ -244,7 +244,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
domainMaxPostsPerDay,accountMaxPostsPerDay, \ domainMaxPostsPerDay,accountMaxPostsPerDay, \
allowDeletion,True,True,False,sendThreads,False) allowDeletion,True,True,False,sendThreads,False)
def createServerBob(path: str,domain: str,port: int,federationList: [], \ def createServerBob(path: str,domain: str,port: int,aliceAddress: str,federationList: [], \
hasFollows: bool,hasPosts :bool,ocapAlways :bool,sendThreads: []): hasFollows: bool,hasPosts :bool,ocapAlways :bool,sendThreads: []):
print('Creating test server: Bob on port '+str(port)) print('Creating test server: Bob on port '+str(port))
if os.path.isdir(path): if os.path.isdir(path):
@ -274,9 +274,9 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
assert setRole(path,nickname,domain,'bandname','publicist') assert setRole(path,nickname,domain,'bandname','publicist')
if hasFollows: if hasFollows:
followPerson(path,nickname,domain, \ followPerson(path,nickname,domain, \
'alice','127.0.0.50:61935',federationList,False) 'alice',aliceAddress,federationList,False)
followerOfPerson(path,nickname,domain, \ followerOfPerson(path,nickname,domain, \
'alice','127.0.0.50:61935',federationList,False) 'alice',aliceAddress,federationList,False)
if hasPosts: if hasPosts:
createPublicPost(path,nickname, domain, port,httpPrefix, \ createPublicPost(path,nickname, domain, port,httpPrefix, \
"It's your life, live it your way.", \ "It's your life, live it your way.", \
@ -357,12 +357,15 @@ def testPostMessageBetweenServers():
aliceDir=baseDir+'/.tests/alice' aliceDir=baseDir+'/.tests/alice'
aliceDomain='127.0.0.50' aliceDomain='127.0.0.50'
alicePort=61935 alicePort=61935
aliceAddress=aliceDomain+':'+str(alicePort)
bobDir=baseDir+'/.tests/bob' bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.100' bobDomain='127.0.0.100'
bobPort=61936 bobPort=61936
federationList=[bobDomain,aliceDomain] federationList=[bobDomain,aliceDomain]
aliceSendThreads=[] aliceSendThreads=[]
bobSendThreads=[] bobSendThreads=[]
bobAddress=bobDomain+':'+str(bobPort)
global thrAlice global thrAlice
if thrAlice: if thrAlice:
@ -373,7 +376,7 @@ def testPostMessageBetweenServers():
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, \ threadWithTrace(target=createServerAlice, \
args=(aliceDir,aliceDomain,alicePort, \ args=(aliceDir,aliceDomain,alicePort,bobAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,aliceSendThreads),daemon=True) ocapAlways,aliceSendThreads),daemon=True)
@ -386,7 +389,7 @@ def testPostMessageBetweenServers():
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, \ threadWithTrace(target=createServerBob, \
args=(bobDir,bobDomain,bobPort, \ args=(bobDir,bobDomain,bobPort,aliceAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,bobSendThreads),daemon=True) ocapAlways,bobSendThreads),daemon=True)
@ -571,9 +574,16 @@ def testFollowBetweenServersWithCapabilities():
# create the servers # create the servers
aliceDir=baseDir+'/.tests/alice' aliceDir=baseDir+'/.tests/alice'
aliceDomain='127.0.0.42' aliceDomain='127.0.0.52'
alicePort=61935 alicePort=61935
aliceSendThreads=[] aliceSendThreads=[]
aliceAddress=aliceDomain+':'+str(alicePort)
bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.78'
bobPort=61936
bobSendThreads=[]
bobAddress=bobDomain+':'+str(bobPort)
global thrAlice global thrAlice
if thrAlice: if thrAlice:
@ -584,15 +594,10 @@ def testFollowBetweenServersWithCapabilities():
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, \ threadWithTrace(target=createServerAlice, \
args=(aliceDir,aliceDomain,alicePort, \ args=(aliceDir,aliceDomain,alicePort,bobAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,aliceSendThreads),daemon=True) ocapAlways,aliceSendThreads),daemon=True)
bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.64'
bobPort=61936
bobSendThreads=[]
global thrBob global thrBob
if thrBob: if thrBob:
while thrBob.isAlive(): while thrBob.isAlive():
@ -602,7 +607,7 @@ def testFollowBetweenServersWithCapabilities():
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, \ threadWithTrace(target=createServerBob, \
args=(bobDir,bobDomain,bobPort, \ args=(bobDir,bobDomain,bobPort,aliceAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,bobSendThreads),daemon=True) ocapAlways,bobSendThreads),daemon=True)
@ -877,9 +882,16 @@ def testFollowBetweenServers():
# create the servers # create the servers
aliceDir=baseDir+'/.tests/alice' aliceDir=baseDir+'/.tests/alice'
aliceDomain='127.0.0.42' aliceDomain='127.0.0.47'
alicePort=61935 alicePort=61935
aliceSendThreads=[] aliceSendThreads=[]
aliceAddress=aliceDomain+':'+str(alicePort)
bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.79'
bobPort=61936
bobSendThreads=[]
bobAddress=bobDomain+':'+str(bobPort)
global thrAlice global thrAlice
if thrAlice: if thrAlice:
@ -890,15 +902,10 @@ def testFollowBetweenServers():
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, \ threadWithTrace(target=createServerAlice, \
args=(aliceDir,aliceDomain,alicePort, \ args=(aliceDir,aliceDomain,alicePort,bobAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,aliceSendThreads),daemon=True) ocapAlways,aliceSendThreads),daemon=True)
bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.64'
bobPort=61936
bobSendThreads=[]
global thrBob global thrBob
if thrBob: if thrBob:
while thrBob.isAlive(): while thrBob.isAlive():
@ -908,7 +915,7 @@ def testFollowBetweenServers():
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, \ threadWithTrace(target=createServerBob, \
args=(bobDir,bobDomain,bobPort, \ args=(bobDir,bobDomain,bobPort,aliceAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,bobSendThreads),daemon=True) ocapAlways,bobSendThreads),daemon=True)
@ -1344,6 +1351,13 @@ def testClientToServer():
aliceDomain='127.0.0.42' aliceDomain='127.0.0.42'
alicePort=61935 alicePort=61935
aliceSendThreads=[] aliceSendThreads=[]
aliceAddress=aliceDomain+':'+str(alicePort)
bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.64'
bobPort=61936
bobSendThreads=[]
bobAddress=bobDomain+':'+str(bobPort)
global thrAlice global thrAlice
if thrAlice: if thrAlice:
@ -1354,15 +1368,10 @@ def testClientToServer():
thrAlice = \ thrAlice = \
threadWithTrace(target=createServerAlice, \ threadWithTrace(target=createServerAlice, \
args=(aliceDir,aliceDomain,alicePort, \ args=(aliceDir,aliceDomain,alicePort,bobAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,aliceSendThreads),daemon=True) ocapAlways,aliceSendThreads),daemon=True)
bobDir=baseDir+'/.tests/bob'
bobDomain='127.0.0.64'
bobPort=61936
bobSendThreads=[]
global thrBob global thrBob
if thrBob: if thrBob:
while thrBob.isAlive(): while thrBob.isAlive():
@ -1372,7 +1381,7 @@ def testClientToServer():
thrBob = \ thrBob = \
threadWithTrace(target=createServerBob, \ threadWithTrace(target=createServerBob, \
args=(bobDir,bobDomain,bobPort, \ args=(bobDir,bobDomain,bobPort,aliceAddress, \
federationList,False,False, \ federationList,False,False, \
ocapAlways,bobSendThreads),daemon=True) ocapAlways,bobSendThreads),daemon=True)

View File

@ -11,13 +11,6 @@ import time
import shutil import shutil
import datetime import datetime
import json import json
import socket
def isPortInUse(portNumber: int) -> bool:
"""Returns true if the port is in use
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(('localhost', portNumber)) == 0
def removeAvatarFromCache(baseDir: str,actorStr: str) -> None: def removeAvatarFromCache(baseDir: str,actorStr: str) -> None:
"""Removes any existing avatar entries from the cache """Removes any existing avatar entries from the cache