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)
|
|
|
|
|
2006-12-04 02:07:41 +00:00
|
|
|
def remote_allocate_bucket(self, verifierid, bucket_num, size, leaser,
|
|
|
|
canary):
|
2006-12-01 03:14:23 +00:00
|
|
|
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,
|
2006-12-04 02:07:41 +00:00
|
|
|
idlib.b2a(leaser), canary)
|
2006-12-01 03:14:23 +00:00
|
|
|
return lease
|
|
|
|
|
2006-12-03 10:01:43 +00:00
|
|
|
def remote_get_buckets(self, verifierid):
|
|
|
|
return self._bucketstore.get_buckets(verifierid)
|