forked from indymedia/epicyon
Fix posts option
parent
b321baf307
commit
fbaf144479
19
inbox.py
19
inbox.py
|
@ -125,7 +125,7 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
|
|||
|
||||
# Try a few times to obtain teh public key
|
||||
pubKey=None
|
||||
for tries in range(5):
|
||||
for tries in range(8):
|
||||
keyId=None
|
||||
signatureParams=queueJson['headers'].split(',')
|
||||
for signatureItem in signatureParams:
|
||||
|
@ -141,13 +141,18 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
|
|||
continue
|
||||
|
||||
pubKey=getPersonPubKey(session,keyId,personCache,debug)
|
||||
if not pubKey:
|
||||
print('********* pubkey7825 '+str(pubKey))
|
||||
if pubKey:
|
||||
print('DEBUG: public key: '+str(pubKey))
|
||||
break
|
||||
|
||||
if debug:
|
||||
print('DEBUG: Retry '+str(tries+1)+' obtaining public key for '+queueJson['keyId'])
|
||||
print('DEBUG: Retry '+str(tries+1)+' obtaining public key for '+keyId)
|
||||
time.sleep(5)
|
||||
|
||||
if not pubKey:
|
||||
if debug:
|
||||
print('DEBUG: public key could not be obtained from '+queueJson['keyId'])
|
||||
print('DEBUG: public key could not be obtained from '+keyId)
|
||||
os.remove(queueFilename)
|
||||
queue.pop(0)
|
||||
continue
|
||||
|
@ -163,18 +168,22 @@ def runInboxQueue(baseDir: str,httpPrefix: str,personCache: {},queue: [],domain:
|
|||
queue.pop(0)
|
||||
continue
|
||||
|
||||
if debug:
|
||||
print('DEBUG: Signature check success')
|
||||
|
||||
if receiveFollowRequest(baseDir, \
|
||||
queueJson.post, \
|
||||
federationList):
|
||||
|
||||
if debug:
|
||||
print('DEBUG: Follow accepted from '+queueJson['keyId'])
|
||||
print('DEBUG: Follow accepted from '+keyId)
|
||||
os.remove(queueFilename)
|
||||
queue.pop(0)
|
||||
continue
|
||||
|
||||
if debug:
|
||||
print('DEBUG: Queue post accepted')
|
||||
|
||||
# move to the destination inbox
|
||||
os.rename(queueFilename,queueJson['destination'])
|
||||
queue.pop(0)
|
||||
|
|
11
posts.py
11
posts.py
|
@ -63,6 +63,8 @@ def getUserUrl(wfRequest) -> str:
|
|||
|
||||
def parseUserFeed(session,feedUrl: str,asHeader: {}) -> None:
|
||||
feedJson = getJson(session,feedUrl,asHeader,None)
|
||||
if not feedJson:
|
||||
return
|
||||
|
||||
if 'orderedItems' in feedJson:
|
||||
for item in feedJson['orderedItems']:
|
||||
|
@ -86,6 +88,8 @@ def getPersonBox(session,wfRequest: {},personCache: {},boxName='inbox') -> (str,
|
|||
personJson = getPersonFromCache(personUrl,personCache)
|
||||
if not personJson:
|
||||
personJson = getJson(session,personUrl,asHeader,None)
|
||||
if not personJson:
|
||||
return None
|
||||
if not personJson.get(boxName):
|
||||
return personPosts
|
||||
personId=None
|
||||
|
@ -113,6 +117,8 @@ def getPersonPubKey(session,personUrl: str,personCache: {},debug: bool) -> str:
|
|||
if debug:
|
||||
print('DEBUG: Obtaining public key for '+personUrl)
|
||||
personJson = getJson(session,personUrl,asHeader,None)
|
||||
if not personJson:
|
||||
return None
|
||||
pubKey=None
|
||||
if personJson.get('publicKey'):
|
||||
if personJson['publicKey'].get('publicKeyPem'):
|
||||
|
@ -644,8 +650,9 @@ def getPublicPostsOfPerson(nickname,domain,raw,simple):
|
|||
cachedWebfingers={}
|
||||
federationList=[]
|
||||
|
||||
handle="https://"+domain+"/@"+nickname
|
||||
wfRequest = webfingerHandle(session,handle,True,cachedWebfingers)
|
||||
httpPrefix='https'
|
||||
handle=httpPrefix+"://"+domain+"/@"+nickname
|
||||
wfRequest = webfingerHandle(session,handle,httpPrefix,cachedWebfingers)
|
||||
if not wfRequest:
|
||||
sys.exit()
|
||||
|
||||
|
|
|
@ -33,9 +33,12 @@ def getJson(session,url: str,headers: {},params: {}) -> {}:
|
|||
sessionParams=params
|
||||
sessionHeaders['User-agent'] = "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48B; wv)"
|
||||
session.cookies.clear()
|
||||
try:
|
||||
result=session.get(url, headers=sessionHeaders, params=sessionParams)
|
||||
#print("*****result "+url+' ' + str(result))
|
||||
return result.json()
|
||||
except:
|
||||
pass
|
||||
return None
|
||||
|
||||
def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers: {}) -> str:
|
||||
"""Post a json message to the inbox of another person
|
||||
|
|
4
tests.py
4
tests.py
|
@ -186,7 +186,7 @@ def testPostMessageBetweenServers():
|
|||
while not (testServerAliceRunning and testServerBobRunning):
|
||||
time.sleep(1)
|
||||
|
||||
time.sleep(6)
|
||||
time.sleep(8)
|
||||
|
||||
print('Alice sends to Bob')
|
||||
os.chdir(aliceDir)
|
||||
|
@ -205,7 +205,7 @@ def testPostMessageBetweenServers():
|
|||
sendResult = sendPost(sessionAlice,aliceDir,'alice', aliceDomain, alicePort, 'bob', bobDomain, bobPort, ccUrl, httpPrefix, 'Why is a mouse when it spins?', followersOnly, saveToFile, clientToServer, federationList, aliceSendThreads, alicePostLog, aliceCachedWebfingers,alicePersonCache,inReplyTo, inReplyToAtomUri, subject)
|
||||
print('sendResult: '+str(sendResult))
|
||||
|
||||
for i in range(10):
|
||||
for i in range(60):
|
||||
time.sleep(1)
|
||||
|
||||
# stop the servers
|
||||
|
|
|
@ -50,9 +50,10 @@ def webfingerHandle(session,handle: str,httpPrefix: str,cachedWebfingers: {}) ->
|
|||
url = '{}://{}/.well-known/webfinger'.format(httpPrefix,domain)
|
||||
par = {'resource': 'acct:{}'.format(nickname+'@'+wfDomain)}
|
||||
hdr = {'Accept': 'application/jrd+json'}
|
||||
#try:
|
||||
try:
|
||||
result = getJson(session, url, hdr, par)
|
||||
#except:
|
||||
except:
|
||||
return None
|
||||
# print("Unable to webfinger " + url + ' ' + str(hdr) + ' ' + str(par))
|
||||
storeWebfingerInCache(nickname+'@'+wfDomain,result,cachedWebfingers)
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue