2006-12-01 03:14:23 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
from foolscap import Referenceable
|
|
|
|
from twisted.application import service
|
|
|
|
|
|
|
|
from allmydata.bucketstore import BucketStore
|
2006-12-02 02:17:50 +00:00
|
|
|
from zope.interface import implements
|
|
|
|
from allmydata.interfaces import RIStorageServer
|
2006-12-03 00:25:57 +00:00
|
|
|
from allmydata.util import idlib
|
2006-12-01 03:14:23 +00:00
|
|
|
|
|
|
|
class BucketAlreadyExistsError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class StorageServer(service.MultiService, Referenceable):
|
2006-12-02 02:17:50 +00:00
|
|
|
implements(RIStorageServer)
|
2006-12-01 03:14:23 +00:00
|
|
|
name = 'storageserver'
|
|
|
|
|
|
|
|
def __init__(self, store_dir):
|
2006-12-01 03:18:29 +00:00
|
|
|
if not os.path.isdir(store_dir):
|
|
|
|
os.mkdir(store_dir)
|
2006-12-01 03:14:23 +00:00
|
|
|
service.MultiService.__init__(self)
|
|
|
|
self._bucketstore = BucketStore(store_dir)
|
|
|
|
self._bucketstore.setServiceParent(self)
|
|
|
|
|
|
|
|
def remote_allocate_bucket(self, verifierid, bucket_num, size, leaser):
|
|
|
|
if self._bucketstore.has_bucket(verifierid):
|
|
|
|
raise BucketAlreadyExistsError()
|
2006-12-03 00:25:57 +00:00
|
|
|
lease = self._bucketstore.allocate_bucket(verifierid, bucket_num, size,
|
|
|
|
idlib.b2a(leaser))
|
2006-12-01 03:14:23 +00:00
|
|
|
return lease
|
|
|
|
|
|
|
|
def remote_get_bucket(self, verifierid):
|
|
|
|
return self._bucketstore.get_bucket(verifierid)
|