diff --git a/README.md b/README.md index 14aa58f58..f74dba452 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This project is currently *pre alpha* and not recommended for any real world use This is one proposed way that OCAP could work. - * Works from person to person, not instance to instance. + * Works from person to person, not instance to instance. Actor-oriented capabilities. * Produces negligible additional network traffic * Works in the same way between people on different instances or the same instance * People can alter what their followers can do on an individual basis diff --git a/acceptreject.py b/acceptreject.py index e6030707e..6e8aae4bc 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -55,9 +55,9 @@ def createAcceptReject(baseDir: str,federationList: [], \ def createAccept(baseDir: str,federationList: [], \ nickname: str,domain: str,port: int, \ toUrl: str,ccUrl: str,httpPrefix: str, \ - objectJson: {}) -> {}: + objectJson: {},acceptedCaps=["inbox:write","objects:read"]) -> {}: # create capabilities accept - ocapNew=capabilitiesAccept(baseDir,httpPrefix,nickname,domain,port,toUrl,True) + ocapNew=capabilitiesAccept(baseDir,httpPrefix,nickname,domain,port,toUrl,True,acceptedCaps) return createAcceptReject(baseDir,federationList, \ nickname,domain,port, \ toUrl,ccUrl,httpPrefix, \ diff --git a/daemon.py b/daemon.py index 5c2cf9503..3c9dafa56 100644 --- a/daemon.py +++ b/daemon.py @@ -497,7 +497,7 @@ class PubServer(BaseHTTPRequestHandler): self.server.POSTbusy=False def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https', \ - fedList=[],ocapAlways=False, \ + fedList=[],noreply=False,nolike=False,ocapAlways=False, \ useTor=False,debug=False) -> None: if len(domain)==0: domain='localhost' @@ -528,6 +528,11 @@ def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https', \ httpd.sendThreads=[] httpd.postLog=[] httpd.ocapAlways=ocapAlways + httpd.acceptedCaps=["inbox:write","objects:read"] + if noreply: + httpd.acceptedCaps.append('inbox:noreply') + if nolike: + httpd.acceptedCaps.append('inbox:nolike') print('Running ActivityPub daemon on ' + domain + ' port ' + str(port)) httpd.thrInboxQueue= \ threadWithTrace(target=runInboxQueue, \ @@ -536,6 +541,6 @@ def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https', \ httpd.personCache,httpd.inboxQueue, \ domain,port,useTor,httpd.federationList, \ httpd.ocapAlways, \ - debug),daemon=True) + debug,httpd.acceptedCaps),daemon=True) httpd.thrInboxQueue.start() httpd.serve_forever() diff --git a/epicyon.py b/epicyon.py index 8e1a029f5..3b86c9206 100644 --- a/epicyon.py +++ b/epicyon.py @@ -117,6 +117,12 @@ parser.add_argument("--testdata", type=str2bool, nargs='?', \ parser.add_argument("--ocap", type=str2bool, nargs='?', \ const=True, default=False, \ help="Always strictly enforce object capabilities") +parser.add_argument("--noreply", type=str2bool, nargs='?', \ + const=True, default=False, \ + help="Default capabilities don't allow replies on posts") +parser.add_argument("--nolike", type=str2bool, nargs='?', \ + const=True, default=False, \ + help="Default capabilities don't allow likes/favourites on posts") args = parser.parse_args() debug=False @@ -410,4 +416,4 @@ if args.testdata: createPublicPost(baseDir,nickname,domain,port,httpPrefix,"another mystery solved hey",False,True,False) createPublicPost(baseDir,nickname,domain,port,httpPrefix,"let's go bowling",False,True,False) -runDaemon(baseDir,domain,port,httpPrefix,federationList,ocapAlways,useTor,debug) +runDaemon(baseDir,domain,port,httpPrefix,federationList,args.noreply,args.nolike,ocapAlways,useTor,debug) diff --git a/follow.py b/follow.py index c8257c6b5..827162b0c 100644 --- a/follow.py +++ b/follow.py @@ -221,7 +221,8 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \ port: int,sendThreads: [],postLog: [], \ cachedWebfingers: {},personCache: {}, \ messageJson: {},federationList: [], \ - debug : bool) -> bool: + debug : bool, \ + acceptedCaps=["inbox:write","objects:read"]) -> bool: """Receives a follow request within the POST section of HTTPServer """ if not messageJson['type'].startswith('Follow'): @@ -283,7 +284,7 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \ personUrl=messageJson['actor'] acceptJson=createAccept(baseDir,federationList, \ nicknameToFollow,domainToFollow,port, \ - personUrl,'',httpPrefix,messageJson) + personUrl,'',httpPrefix,messageJson,acceptedCaps) if debug: pprint(acceptJson) print('DEBUG: sending follow Accept from '+ \ diff --git a/inbox.py b/inbox.py index c7fdd5503..575b63df4 100644 --- a/inbox.py +++ b/inbox.py @@ -347,7 +347,7 @@ def receiveUpdate(session,baseDir: str, \ return True return False -def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cachedWebfingers: {},personCache: {},queue: [],domain: str,port: int,useTor: bool,federationList: [],ocapAlways: bool,debug: bool) -> None: +def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cachedWebfingers: {},personCache: {},queue: [],domain: str,port: int,useTor: bool,federationList: [],ocapAlways: bool,debug: bool,acceptedCaps=["inbox:write","objects:read"]) -> None: """Processes received items and moves them to the appropriate directories """ @@ -438,7 +438,8 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache personCache, queueJson['post'], \ federationList, \ - debug): + debug, \ + acceptedCaps=["inbox:write","objects:read"]): if debug: print('DEBUG: Follow accepted from '+keyId) os.remove(queueFilename) diff --git a/tests.py b/tests.py index 034e96434..db05bcf81 100644 --- a/tests.py +++ b/tests.py @@ -125,6 +125,8 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [],hasFoll useTor=False clientToServer=False password='alicepass' + noreply=False + nolike=False privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password) deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'outbox') @@ -138,7 +140,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [],hasFoll global testServerAliceRunning testServerAliceRunning = True print('Server running: Alice') - runDaemon(path,domain,port,httpPrefix,federationList,ocapAlways,useTor,True) + runDaemon(path,domain,port,httpPrefix,federationList,noreply,nolike,ocapAlways,useTor,True) def createServerBob(path: str,domain: str,port: int,federationList: [],hasFollows: bool,hasPosts :bool,ocapAlways :bool): print('Creating test server: Bob on port '+str(port)) @@ -151,6 +153,8 @@ def createServerBob(path: str,domain: str,port: int,federationList: [],hasFollow useTor=False clientToServer=False password='bobpass' + noreply=False + nolike=False privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password) deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'outbox') @@ -164,7 +168,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [],hasFollow global testServerBobRunning testServerBobRunning = True print('Server running: Bob') - runDaemon(path,domain,port,httpPrefix,federationList,ocapAlways,useTor,True) + runDaemon(path,domain,port,httpPrefix,federationList,noreply,nolike,ocapAlways,useTor,True) def createServerEve(path: str,domain: str,port: int,federationList: [],hasFollows: bool,hasPosts :bool,ocapAlways :bool): print('Creating test server: Eve on port '+str(port)) @@ -177,13 +181,15 @@ def createServerEve(path: str,domain: str,port: int,federationList: [],hasFollow useTor=False clientToServer=False password='evepass' + noreply=False + nolike=False privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password) deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'outbox') global testServerEveRunning testServerEveRunning = True print('Server running: Eve') - runDaemon(path,domain,port,httpPrefix,federationList,ocapAlways,useTor,True) + runDaemon(path,domain,port,httpPrefix,federationList,noreply,nolike,ocapAlways,useTor,True) def testPostMessageBetweenServers(): print('Testing sending message from one server to the inbox of another')