forked from indymedia/epicyon
Check that announce activity arrives
parent
ca0db9e45f
commit
5d80b5adbc
58
inbox.py
58
inbox.py
|
@ -438,6 +438,52 @@ def receiveLike(session,handle: str,baseDir: str, \
|
||||||
updateLikesCollection(postFilename,messageJson['object'],messageJson['actor'],debug)
|
updateLikesCollection(postFilename,messageJson['object'],messageJson['actor'],debug)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def receiveAnnounce(session,handle: str,baseDir: str, \
|
||||||
|
httpPrefix: str,domain :str,port: int, \
|
||||||
|
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
||||||
|
personCache: {},messageJson: {},federationList: [], \
|
||||||
|
debug : bool) -> bool:
|
||||||
|
"""Receives a Like activity within the POST section of HTTPServer
|
||||||
|
"""
|
||||||
|
if messageJson['type']!='Announce':
|
||||||
|
return False
|
||||||
|
if not messageJson.get('actor'):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' has no actor')
|
||||||
|
return False
|
||||||
|
if not messageJson.get('object'):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' has no object')
|
||||||
|
return False
|
||||||
|
if not isinstance(messageJson['object'], str):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' object is not a string')
|
||||||
|
return False
|
||||||
|
if not messageJson.get('to'):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: '+messageJson['type']+' has no "to" list')
|
||||||
|
return False
|
||||||
|
if '/users/' not in messageJson['actor']:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: "users" missing from actor in '+messageJson['type'])
|
||||||
|
return False
|
||||||
|
if '/statuses/' not in messageJson['object']:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: "statuses" missing from object in '+messageJson['type'])
|
||||||
|
return False
|
||||||
|
if not os.path.isdir(baseDir+'/accounts/'+handle):
|
||||||
|
print('DEBUG: unknown recipient of announce - '+handle)
|
||||||
|
# if this post in the outbox of the person?
|
||||||
|
postFilename=locatePost(baseDir,handle.split('@')[0],handle.split('@')[1],messageJson['object'])
|
||||||
|
if not postFilename:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: announce post not found in inbox or outbox')
|
||||||
|
print(messageJson['object'])
|
||||||
|
return True
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: announced/repeated post found in inbox')
|
||||||
|
return True
|
||||||
|
|
||||||
def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
baseDir: str,httpPrefix: str,sendThreads: [], \
|
baseDir: str,httpPrefix: str,sendThreads: [], \
|
||||||
postLog: [],cachedWebfingers: {},personCache: {}, \
|
postLog: [],cachedWebfingers: {},personCache: {}, \
|
||||||
|
@ -460,6 +506,18 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
print('DEBUG: Like accepted from '+keyId)
|
print('DEBUG: Like accepted from '+keyId)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if receiveAnnounce(session,handle, \
|
||||||
|
baseDir,httpPrefix, \
|
||||||
|
domain,port, \
|
||||||
|
sendThreads,postLog, \
|
||||||
|
cachedWebfingers, \
|
||||||
|
personCache, \
|
||||||
|
messageJson, \
|
||||||
|
federationList, \
|
||||||
|
debug):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: Announce accepted from '+keyId)
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: object capabilities passed')
|
print('DEBUG: object capabilities passed')
|
||||||
print('copy from '+queueFilename+' to '+destinationFilename)
|
print('copy from '+queueFilename+' to '+destinationFilename)
|
||||||
|
|
16
tests.py
16
tests.py
|
@ -318,13 +318,27 @@ def testPostMessageBetweenServers():
|
||||||
print('\n\n*******************************************************')
|
print('\n\n*******************************************************')
|
||||||
print("Bob repeats Alice's post")
|
print("Bob repeats Alice's post")
|
||||||
objectUrl=httpPrefix+'://'+aliceDomain+':'+str(alicePort)+'/users/alice/statuses/'+str(statusNumber)
|
objectUrl=httpPrefix+'://'+aliceDomain+':'+str(alicePort)+'/users/alice/statuses/'+str(statusNumber)
|
||||||
|
inboxPath=aliceDir+'/accounts/alice@'+aliceDomain+'/inbox'
|
||||||
|
beforeAnnounceCount=len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])
|
||||||
|
assert beforeAnnounceCount==0
|
||||||
|
print('inbox items before announce: '+str(beforeAnnounceCount))
|
||||||
announcePublic(sessionBob,bobDir,federationList, \
|
announcePublic(sessionBob,bobDir,federationList, \
|
||||||
'bob',bobDomain,bobPort,httpPrefix, \
|
'bob',bobDomain,bobPort,httpPrefix, \
|
||||||
objectUrl, \
|
objectUrl, \
|
||||||
False,bobSendThreads,bobPostLog, \
|
False,bobSendThreads,bobPostLog, \
|
||||||
bobPersonCache,bobCachedWebfingers, \
|
bobPersonCache,bobCachedWebfingers, \
|
||||||
True)
|
True)
|
||||||
|
announceMessageArrived=False
|
||||||
|
for i in range(10):
|
||||||
|
time.sleep(1)
|
||||||
|
if os.path.isdir(inboxPath):
|
||||||
|
if len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])>0:
|
||||||
|
announceMessageArrived=True
|
||||||
|
print('Announce message sent to Alice!')
|
||||||
|
break
|
||||||
|
afterAnnounceCount=len([name for name in os.listdir(inboxPath) if os.path.isfile(os.path.join(inboxPath, name))])
|
||||||
|
print('inbox items after announce: '+str(afterAnnounceCount))
|
||||||
|
assert afterAnnounceCount==beforeAnnounceCount+1
|
||||||
# stop the servers
|
# stop the servers
|
||||||
thrAlice.kill()
|
thrAlice.kill()
|
||||||
thrAlice.join()
|
thrAlice.join()
|
||||||
|
|
11
utils.py
11
utils.py
|
@ -121,15 +121,16 @@ def followPerson(baseDir: str,nickname: str, domain: str, \
|
||||||
def locatePost(baseDir: str,nickname: str,domain: str,postUrl: str):
|
def locatePost(baseDir: str,nickname: str,domain: str,postUrl: str):
|
||||||
"""Returns the filename for the given status post url
|
"""Returns the filename for the given status post url
|
||||||
"""
|
"""
|
||||||
boxName='outbox'
|
# if this post in the shared inbox?
|
||||||
|
handle='inbox@'+domain
|
||||||
|
boxName='inbox'
|
||||||
postFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/'+boxName+'/'+postUrl.replace('/','#')+'.json'
|
postFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/'+boxName+'/'+postUrl.replace('/','#')+'.json'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
# if this post in the inbox of the person?
|
boxName='outbox'
|
||||||
boxName='inbox'
|
|
||||||
postFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/'+boxName+'/'+postUrl.replace('/','#')+'.json'
|
postFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/'+boxName+'/'+postUrl.replace('/','#')+'.json'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
# if this post in the shared inbox?
|
# if this post in the inbox of the person?
|
||||||
handle='inbox@'+domain
|
boxName='inbox'
|
||||||
postFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/'+boxName+'/'+postUrl.replace('/','#')+'.json'
|
postFilename=baseDir+'/accounts/'+nickname+'@'+domain+'/'+boxName+'/'+postUrl.replace('/','#')+'.json'
|
||||||
if not os.path.isfile(postFilename):
|
if not os.path.isfile(postFilename):
|
||||||
postFilename=None
|
postFilename=None
|
||||||
|
|
Loading…
Reference in New Issue