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:
return
acceptedDomainFull=acceptedDomain
if acceptedPort:
acceptedDomainFull=acceptedDomain+':'+str(acceptedPort)
# are capabilities attached? If so then store them
if messageJson.get('capabilities'):
if isinstance(messageJson['capabilities'], dict):
acceptedDomainFull=acceptedDomain
if acceptedPort:
acceptedDomainFull=acceptedDomain+':'+str(acceptedPort)
capabilitiesGrantedSave(baseDir, \
nickname,acceptedDomainFull, \
messageJson['capabilities'])
if followPerson(baseDir, \
nickname,acceptedDomain, \
followedNickname,followedDomain, \
nickname,acceptedDomainFull, \
followedNickname,followedDomainFull, \
federationList,debug):
if debug:
print('DEBUG: '+nickname+'@'+acceptedDomain+' followed '+followedNickname+'@'+followedDomain)
print('DEBUG: '+nickname+'@'+acceptedDomainFull+' followed '+followedNickname+'@'+followedDomainFull)
else:
if debug:
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
domain,tempPort=getDomainFromActor(messageJson['actor'])
fromPort=port
domainFull=domain
if tempPort:
fromPort=tempPort
if tempPort!=80 and tempPort!=443:
domainFull=domain+':'+str(tempPort)
if not domainPermitted(domain,federationList):
if debug:
print('DEBUG: follower from domain not permitted - '+domain)
@ -264,6 +267,10 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
if debug:
print('DEBUG: follow domain not permitted '+domainToFollow)
return False
domainToFollowFull=domainToFollow
if tempPort:
if tempPort!=80 and tempPort!=443:
domainToFollowFull=domainToFollow+':'+str(tempPort)
nicknameToFollow=getNicknameFromActor(messageJson['object'])
if not nicknameToFollow:
if debug:
@ -276,8 +283,10 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
print('DEBUG: followed account not found - '+ \
baseDir+'/accounts/'+handleToFollow)
return False
if not followerOfPerson(baseDir,nicknameToFollow,domainToFollow, \
nickname,domain,federationList,debug):
if not followerOfPerson(baseDir,nicknameToFollow,domainToFollowFull, \
nickname,domainFull,federationList,debug):
if debug:
print('DEBUG: '+nickname+'@'+domain+ \
' is already a follower of '+ \

View File

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

View File

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

View File

@ -1091,19 +1091,23 @@ def testClientToServer():
sessionBob = createSession(bobDomain,bobPort,useTor)
password='bobpass'
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(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==0
sendAnnounceViaServer(sessionBob,'bob',password, \
bobDomain,bobPort, \
httpPrefix,outboxPostId, \
cachedWebfingers, \
personCache,True)
for i in range(10):
if os.path.isdir(outboxPath):
for i in range(20):
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:
break
if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1:
break
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(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])==1
print('Post repeated')
# stop the servers

View File

@ -98,8 +98,16 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
return False
if debug:
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'):
os.mkdir(baseDir+'/accounts')
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')
return True
with open(filename, "a") as followfile:
followfile.write(handleToFollow+'\n')
followfile.write(followNickname+'@'+followDomain+'\n')
if debug:
print('DEBUG: follow added')
return True
if debug:
print('DEBUG: creating new following file')
with open(filename, "w") as followfile:
followfile.write(handleToFollow+'\n')
followfile.write(followNickname+'@'+followDomain+'\n')
return True
def locatePost(baseDir: str,nickname: str,domain: str,postUrl: str,replies=False) -> str: