From 4298de739e89cb16d493ffa991b2889341dbc22c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 3 Jan 2020 16:52:31 +0000 Subject: [PATCH] Limit the number of manual follow requests --- follow.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/follow.py b/follow.py index 4b38182d..85ca2371 100644 --- a/follow.py +++ b/follow.py @@ -370,6 +370,26 @@ def followApprovalRequired(baseDir: str,nicknameToFollow: str, \ print('DEBUG: Actor file not found: '+actorFilename) return manuallyApproveFollows +def noOfFollowRequests(baseDir: str, \ + nicknameToFollow: str,domainToFollow: str, \ + nickname: str,domain: str,fromPort: int, \ + followType: str) -> int: + """Returns the current number of follow requests + """ + accountsDir=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow + approveFollowsFilename=accountsDir+'/followrequests.txt' + if not os.path.isfile(approveFollowsFilename): + return 0 + ctr=0 + with open(approveFollowsFilename, "r") as f: + lines = f.readlines() + if followType != "onion": + return len(lines) + for l in lines: + if '.onion' in l: + ctr+=1 + return ctr + def storeFollowRequest(baseDir: str, \ nicknameToFollow: str,domainToFollow: str,port: int, \ nickname: str,domain: str,fromPort: int, \ @@ -509,6 +529,19 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \ approveHandle=nickname+'@'+domainFull if followApprovalRequired(baseDir,nicknameToFollow, \ domainToFollow,debug,approveHandle): + if not domain.endswith('.onion'): + if noOfFollowRequests(baseDir, \ + nicknameToFollow, \ + domainToFollow,'') > 10: + print('Too many follow requests') + return False + else: + if noOfFollowRequests(baseDir, \ + nicknameToFollow, \ + domainToFollow,'onion') > 5: + print('Too many follow requests from onion addresses') + return False + print('Storing follow request for approval') return storeFollowRequest(baseDir, \ nicknameToFollow,domainToFollow,port, \