diff --git a/inbox.py b/inbox.py index b3442dac4..b7d79dab7 100644 --- a/inbox.py +++ b/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: - if debug: - print('DEBUG: Retry '+str(tries+1)+' obtaining public key for '+queueJson['keyId']) - time.sleep(5) + 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 '+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) diff --git a/posts.py b/posts.py index f330ba7dd..f4707145a 100644 --- a/posts.py +++ b/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() diff --git a/session.py b/session.py index 0a2d7a28e..37dca3f0b 100644 --- a/session.py +++ b/session.py @@ -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() - result=session.get(url, headers=sessionHeaders, params=sessionParams) - #print("*****result "+url+' ' + str(result)) - return result.json() + try: + result=session.get(url, headers=sessionHeaders, params=sessionParams) + 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 diff --git a/tests.py b/tests.py index 9514eb43e..571794a94 100644 --- a/tests.py +++ b/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 diff --git a/webfinger.py b/webfinger.py index 0d20be27c..d1d319633 100644 --- a/webfinger.py +++ b/webfinger.py @@ -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: - result = getJson(session, url, hdr, par) - #except: + try: + result = getJson(session, url, hdr, par) + except: + return None # print("Unable to webfinger " + url + ' ' + str(hdr) + ' ' + str(par)) storeWebfingerInCache(nickname+'@'+wfDomain,result,cachedWebfingers) return result