Set default capabilities with options

master
Bob Mottram 2019-07-09 18:54:08 +01:00
parent 639403a37e
commit 21a72b59fc
7 changed files with 32 additions and 13 deletions

View File

@ -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. 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 * Produces negligible additional network traffic
* Works in the same way between people on different instances or the same instance * 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 * People can alter what their followers can do on an individual basis

View File

@ -55,9 +55,9 @@ def createAcceptReject(baseDir: str,federationList: [], \
def createAccept(baseDir: str,federationList: [], \ def createAccept(baseDir: str,federationList: [], \
nickname: str,domain: str,port: int, \ nickname: str,domain: str,port: int, \
toUrl: str,ccUrl: str,httpPrefix: str, \ toUrl: str,ccUrl: str,httpPrefix: str, \
objectJson: {}) -> {}: objectJson: {},acceptedCaps=["inbox:write","objects:read"]) -> {}:
# create capabilities accept # 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, \ return createAcceptReject(baseDir,federationList, \
nickname,domain,port, \ nickname,domain,port, \
toUrl,ccUrl,httpPrefix, \ toUrl,ccUrl,httpPrefix, \

View File

@ -497,7 +497,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy=False self.server.POSTbusy=False
def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https', \ 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: useTor=False,debug=False) -> None:
if len(domain)==0: if len(domain)==0:
domain='localhost' domain='localhost'
@ -528,6 +528,11 @@ def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https', \
httpd.sendThreads=[] httpd.sendThreads=[]
httpd.postLog=[] httpd.postLog=[]
httpd.ocapAlways=ocapAlways 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)) print('Running ActivityPub daemon on ' + domain + ' port ' + str(port))
httpd.thrInboxQueue= \ httpd.thrInboxQueue= \
threadWithTrace(target=runInboxQueue, \ threadWithTrace(target=runInboxQueue, \
@ -536,6 +541,6 @@ def runDaemon(baseDir: str,domain: str,port=80,httpPrefix='https', \
httpd.personCache,httpd.inboxQueue, \ httpd.personCache,httpd.inboxQueue, \
domain,port,useTor,httpd.federationList, \ domain,port,useTor,httpd.federationList, \
httpd.ocapAlways, \ httpd.ocapAlways, \
debug),daemon=True) debug,httpd.acceptedCaps),daemon=True)
httpd.thrInboxQueue.start() httpd.thrInboxQueue.start()
httpd.serve_forever() httpd.serve_forever()

View File

@ -117,6 +117,12 @@ parser.add_argument("--testdata", type=str2bool, nargs='?', \
parser.add_argument("--ocap", type=str2bool, nargs='?', \ parser.add_argument("--ocap", type=str2bool, nargs='?', \
const=True, default=False, \ const=True, default=False, \
help="Always strictly enforce object capabilities") 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() args = parser.parse_args()
debug=False 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,"another mystery solved hey",False,True,False)
createPublicPost(baseDir,nickname,domain,port,httpPrefix,"let's go bowling",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)

View File

@ -221,7 +221,8 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
port: int,sendThreads: [],postLog: [], \ port: int,sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
messageJson: {},federationList: [], \ messageJson: {},federationList: [], \
debug : bool) -> bool: debug : bool, \
acceptedCaps=["inbox:write","objects:read"]) -> bool:
"""Receives a follow request within the POST section of HTTPServer """Receives a follow request within the POST section of HTTPServer
""" """
if not messageJson['type'].startswith('Follow'): if not messageJson['type'].startswith('Follow'):
@ -283,7 +284,7 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
personUrl=messageJson['actor'] personUrl=messageJson['actor']
acceptJson=createAccept(baseDir,federationList, \ acceptJson=createAccept(baseDir,federationList, \
nicknameToFollow,domainToFollow,port, \ nicknameToFollow,domainToFollow,port, \
personUrl,'',httpPrefix,messageJson) personUrl,'',httpPrefix,messageJson,acceptedCaps)
if debug: if debug:
pprint(acceptJson) pprint(acceptJson)
print('DEBUG: sending follow Accept from '+ \ print('DEBUG: sending follow Accept from '+ \

View File

@ -347,7 +347,7 @@ def receiveUpdate(session,baseDir: str, \
return True return True
return False 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 """Processes received items and moves them to
the appropriate directories the appropriate directories
""" """
@ -438,7 +438,8 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache
personCache, personCache,
queueJson['post'], \ queueJson['post'], \
federationList, \ federationList, \
debug): debug, \
acceptedCaps=["inbox:write","objects:read"]):
if debug: if debug:
print('DEBUG: Follow accepted from '+keyId) print('DEBUG: Follow accepted from '+keyId)
os.remove(queueFilename) os.remove(queueFilename)

View File

@ -125,6 +125,8 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [],hasFoll
useTor=False useTor=False
clientToServer=False clientToServer=False
password='alicepass' password='alicepass'
noreply=False
nolike=False
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password) privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password)
deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'inbox')
deleteAllPosts(path,nickname,domain,'outbox') deleteAllPosts(path,nickname,domain,'outbox')
@ -138,7 +140,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [],hasFoll
global testServerAliceRunning global testServerAliceRunning
testServerAliceRunning = True testServerAliceRunning = True
print('Server running: Alice') 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): def createServerBob(path: str,domain: str,port: int,federationList: [],hasFollows: bool,hasPosts :bool,ocapAlways :bool):
print('Creating test server: Bob on port '+str(port)) 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 useTor=False
clientToServer=False clientToServer=False
password='bobpass' password='bobpass'
noreply=False
nolike=False
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password) privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password)
deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'inbox')
deleteAllPosts(path,nickname,domain,'outbox') deleteAllPosts(path,nickname,domain,'outbox')
@ -164,7 +168,7 @@ def createServerBob(path: str,domain: str,port: int,federationList: [],hasFollow
global testServerBobRunning global testServerBobRunning
testServerBobRunning = True testServerBobRunning = True
print('Server running: Bob') 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): def createServerEve(path: str,domain: str,port: int,federationList: [],hasFollows: bool,hasPosts :bool,ocapAlways :bool):
print('Creating test server: Eve on port '+str(port)) 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 useTor=False
clientToServer=False clientToServer=False
password='evepass' password='evepass'
noreply=False
nolike=False
privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password) privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(path,nickname,domain,port,httpPrefix,True,password)
deleteAllPosts(path,nickname,domain,'inbox') deleteAllPosts(path,nickname,domain,'inbox')
deleteAllPosts(path,nickname,domain,'outbox') deleteAllPosts(path,nickname,domain,'outbox')
global testServerEveRunning global testServerEveRunning
testServerEveRunning = True testServerEveRunning = True
print('Server running: Eve') 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(): def testPostMessageBetweenServers():
print('Testing sending message from one server to the inbox of another') print('Testing sending message from one server to the inbox of another')