Fix follower ports

master
Bob Mottram 2019-07-16 23:57:45 +01:00
parent f02839e32f
commit 3813809958
6 changed files with 60 additions and 16 deletions

View File

@ -137,22 +137,23 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
if not followedNickname: if not followedNickname:
return return
acceptedDomainFull=acceptedDomain
if acceptedPort:
acceptedDomainFull=acceptedDomain+':'+str(acceptedPort)
# are capabilities attached? If so then store them # are capabilities attached? If so then store them
if messageJson.get('capabilities'): if messageJson.get('capabilities'):
if isinstance(messageJson['capabilities'], dict): if isinstance(messageJson['capabilities'], dict):
acceptedDomainFull=acceptedDomain
if acceptedPort:
acceptedDomainFull=acceptedDomain+':'+str(acceptedPort)
capabilitiesGrantedSave(baseDir, \ capabilitiesGrantedSave(baseDir, \
nickname,acceptedDomainFull, \ nickname,acceptedDomainFull, \
messageJson['capabilities']) messageJson['capabilities'])
if followPerson(baseDir, \ if followPerson(baseDir, \
nickname,acceptedDomain, \ nickname,acceptedDomainFull, \
followedNickname,followedDomain, \ followedNickname,followedDomainFull, \
federationList,debug): federationList,debug):
if debug: if debug:
print('DEBUG: '+nickname+'@'+acceptedDomain+' followed '+followedNickname+'@'+followedDomain) print('DEBUG: '+nickname+'@'+acceptedDomainFull+' followed '+followedNickname+'@'+followedDomainFull)
else: else:
if debug: if debug:
print('DEBUG: Unable to create follow - '+nickname+'@'+acceptedDomain+' -> '+followedNickname+'@'+followedDomain) print('DEBUG: Unable to create follow - '+nickname+'@'+acceptedDomain+' -> '+followedNickname+'@'+followedDomain)

View File

@ -243,8 +243,11 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
return False return False
domain,tempPort=getDomainFromActor(messageJson['actor']) domain,tempPort=getDomainFromActor(messageJson['actor'])
fromPort=port fromPort=port
domainFull=domain
if tempPort: if tempPort:
fromPort=tempPort fromPort=tempPort
if tempPort!=80 and tempPort!=443:
domainFull=domain+':'+str(tempPort)
if not domainPermitted(domain,federationList): if not domainPermitted(domain,federationList):
if debug: if debug:
print('DEBUG: follower from domain not permitted - '+domain) print('DEBUG: follower from domain not permitted - '+domain)
@ -264,6 +267,10 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
if debug: if debug:
print('DEBUG: follow domain not permitted '+domainToFollow) print('DEBUG: follow domain not permitted '+domainToFollow)
return False return False
domainToFollowFull=domainToFollow
if tempPort:
if tempPort!=80 and tempPort!=443:
domainToFollowFull=domainToFollow+':'+str(tempPort)
nicknameToFollow=getNicknameFromActor(messageJson['object']) nicknameToFollow=getNicknameFromActor(messageJson['object'])
if not nicknameToFollow: if not nicknameToFollow:
if debug: if debug:
@ -276,8 +283,10 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
print('DEBUG: followed account not found - '+ \ print('DEBUG: followed account not found - '+ \
baseDir+'/accounts/'+handleToFollow) baseDir+'/accounts/'+handleToFollow)
return False return False
if not followerOfPerson(baseDir,nicknameToFollow,domainToFollow, \
nickname,domain,federationList,debug):
if not followerOfPerson(baseDir,nicknameToFollow,domainToFollowFull, \
nickname,domainFull,federationList,debug):
if debug: if debug:
print('DEBUG: '+nickname+'@'+domain+ \ print('DEBUG: '+nickname+'@'+domain+ \
' is already a follower of '+ \ ' is already a follower of '+ \

View File

@ -582,6 +582,8 @@ def receiveAnnounce(session,handle: str,baseDir: str, \
if debug: if debug:
print('DEBUG: '+messageJson['type']+' has no actor') print('DEBUG: '+messageJson['type']+' has no actor')
return False return False
if debug:
print('DEBUG: receiving announce on '+handle)
if not messageJson.get('object'): if not messageJson.get('object'):
if debug: if debug:
print('DEBUG: '+messageJson['type']+' has no object') print('DEBUG: '+messageJson['type']+' has no object')

View File

@ -788,6 +788,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
personCache: {}, debug: bool) -> int: personCache: {}, debug: bool) -> int:
"""Sends a signed json object to an inbox/outbox """Sends a signed json object to an inbox/outbox
""" """
if debug:
print('DEBUG: sendSignedJson start')
if not session: if not session:
print('WARN: No session specified for sendSignedJson') print('WARN: No session specified for sendSignedJson')
return 8 return 8
@ -802,6 +804,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
toDomain=toDomain+':'+str(toPort) toDomain=toDomain+':'+str(toPort)
handle=httpPrefix+'://'+toDomain+'/@'+toNickname handle=httpPrefix+'://'+toDomain+'/@'+toNickname
if debug:
print('DEBUG: handle - '+handle+' toPort '+str(toPort))
# lookup the inbox for the To handle # lookup the inbox for the To handle
wfRequest=webfingerHandle(session,handle,httpPrefix,cachedWebfingers) wfRequest=webfingerHandle(session,handle,httpPrefix,cachedWebfingers)
@ -831,10 +835,16 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
print('DEBUG: Sending to endpoint '+inboxUrl) print('DEBUG: Sending to endpoint '+inboxUrl)
if not inboxUrl: if not inboxUrl:
if debug:
print('DEBUG: missing inboxUrl')
return 3 return 3
if not pubKey: if not pubKey:
if debug:
print('DEBUG: missing pubkey')
return 4 return 4
if not toPersonId: if not toPersonId:
if debug:
print('DEBUG: missing personId')
return 5 return 5
# sharedInbox and capabilities are optional # sharedInbox and capabilities are optional
@ -846,6 +856,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
return 6 return 6
if toDomain not in inboxUrl: if toDomain not in inboxUrl:
if debug:
print('DEBUG: '+toDomain+' not in '+inboxUrl)
return 7 return 7
postPath='/'+inboxUrl.split('/')[-1] postPath='/'+inboxUrl.split('/')[-1]
@ -858,6 +870,8 @@ def sendSignedJson(postJsonObject: {},session,baseDir: str, \
while len(sendThreads)>10: while len(sendThreads)>10:
sendThreads[0].kill() sendThreads[0].kill()
sendThreads.pop(0) sendThreads.pop(0)
if debug:
print('DEBUG: starting thread to send post')
thr = threadWithTrace(target=threadSendPost, \ thr = threadWithTrace(target=threadSendPost, \
args=(session, \ args=(session, \
postJsonObject.copy(), \ postJsonObject.copy(), \
@ -964,6 +978,9 @@ def sendToFollowers(session,baseDir: str, \
# for each instance # for each instance
for followerDomain,followerHandles in grouped.items(): for followerDomain,followerHandles in grouped.items():
if debug:
print('DEBUG: follower handles for '+followerDomain)
pprint(followerHandles)
toPort=port toPort=port
index=0 index=0
toDomain=followerHandles[index].split('@')[1] toDomain=followerHandles[index].split('@')[1]
@ -976,7 +993,7 @@ def sendToFollowers(session,baseDir: str, \
nickname='inbox' nickname='inbox'
toNickname='inbox' toNickname='inbox'
if debug: if debug:
print('Sending from '+nickname+'@'+domain+' to '+toNickname+'@'+toDomain) print('DEBUG: Sending from '+nickname+'@'+domain+' to '+toNickname+'@'+toDomain)
sendSignedJson(postJsonObject,session,baseDir, \ sendSignedJson(postJsonObject,session,baseDir, \
nickname,domain,port, \ nickname,domain,port, \
toNickname,toDomain,toPort, \ toNickname,toDomain,toPort, \
@ -984,6 +1001,9 @@ def sendToFollowers(session,baseDir: str, \
federationList, \ federationList, \
sendThreads,postLog,cachedWebfingers, \ sendThreads,postLog,cachedWebfingers, \
personCache,debug) personCache,debug)
if debug:
print('DEBUG: End of sendToFollowers')
def createInbox(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \ def createInbox(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,ocapAlways: bool,pageNumber=None) -> {}: itemsPerPage: int,headerOnly: bool,ocapAlways: bool,pageNumber=None) -> {}:

View File

@ -1091,19 +1091,23 @@ def testClientToServer():
sessionBob = createSession(bobDomain,bobPort,useTor) sessionBob = createSession(bobDomain,bobPort,useTor)
password='bobpass' password='bobpass'
outboxPath=bobDir+'/accounts/bob@'+bobDomain+'/outbox' outboxPath=bobDir+'/accounts/bob@'+bobDomain+'/outbox'
inboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/inbox'
assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0 assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==0
assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==0
sendAnnounceViaServer(sessionBob,'bob',password, \ sendAnnounceViaServer(sessionBob,'bob',password, \
bobDomain,bobPort, \ bobDomain,bobPort, \
httpPrefix,outboxPostId, \ httpPrefix,outboxPostId, \
cachedWebfingers, \ cachedWebfingers, \
personCache,True) personCache,True)
for i in range(10): for i in range(20):
if os.path.isdir(outboxPath): if os.path.isdir(outboxPath) and os.path.isdir(inboxPath):
if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1: if len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1:
break if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1:
break
time.sleep(1) time.sleep(1)
assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1 assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))])==1
assert len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1
print('Post repeated') print('Post repeated')
# stop the servers # stop the servers

View File

@ -98,8 +98,16 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
return False return False
if debug: if debug:
print('DEBUG: follow of domain '+followDomain) print('DEBUG: follow of domain '+followDomain)
handle=nickname.lower()+'@'+domain.lower()
handleToFollow=followNickname.lower()+'@'+followDomain.lower() if ':' in domain:
handle=nickname+'@'+domain.split(':')[0].lower()
else:
handle=nickname+'@'+domain.lower()
if ':' in followDomain:
handleToFollow=followNickname+'@'+followDomain.split(':')[0].lower()
else:
handleToFollow=followNickname+'@'+followDomain.lower()
if not os.path.isdir(baseDir+'/accounts'): if not os.path.isdir(baseDir+'/accounts'):
os.mkdir(baseDir+'/accounts') os.mkdir(baseDir+'/accounts')
if not os.path.isdir(baseDir+'/accounts/'+handle): if not os.path.isdir(baseDir+'/accounts/'+handle):
@ -111,14 +119,14 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
print('DEBUG: follow already exists') print('DEBUG: follow already exists')
return True return True
with open(filename, "a") as followfile: with open(filename, "a") as followfile:
followfile.write(handleToFollow+'\n') followfile.write(followNickname+'@'+followDomain+'\n')
if debug: if debug:
print('DEBUG: follow added') print('DEBUG: follow added')
return True return True
if debug: if debug:
print('DEBUG: creating new following file') print('DEBUG: creating new following file')
with open(filename, "w") as followfile: with open(filename, "w") as followfile:
followfile.write(handleToFollow+'\n') followfile.write(followNickname+'@'+followDomain+'\n')
return True return True
def locatePost(baseDir: str,nickname: str,domain: str,postUrl: str,replies=False) -> str: def locatePost(baseDir: str,nickname: str,domain: str,postUrl: str,replies=False) -> str: