2007-12-03 21:52:42 +00:00
|
|
|
|
|
|
|
from zope.interface import implements
|
2007-12-04 04:37:54 +00:00
|
|
|
from twisted.internet import defer
|
2008-07-16 00:23:25 +00:00
|
|
|
from allmydata.interfaces import IFileNode, IFileURI, IURI, ICheckable
|
2007-12-04 04:37:54 +00:00
|
|
|
from allmydata import uri
|
2008-09-07 19:44:56 +00:00
|
|
|
from allmydata.immutable.checker import SimpleCHKFileChecker, \
|
|
|
|
SimpleCHKFileVerifier
|
2007-12-03 21:52:42 +00:00
|
|
|
|
|
|
|
class FileNode:
|
2008-07-16 00:23:25 +00:00
|
|
|
implements(IFileNode, ICheckable)
|
2008-07-17 23:47:09 +00:00
|
|
|
checker_class = SimpleCHKFileChecker
|
|
|
|
verifier_class = SimpleCHKFileVerifier
|
2007-12-03 21:52:42 +00:00
|
|
|
|
|
|
|
def __init__(self, uri, client):
|
|
|
|
u = IFileURI(uri)
|
2008-07-17 23:47:09 +00:00
|
|
|
self.u = u
|
2007-12-03 21:52:42 +00:00
|
|
|
self.uri = u.to_string()
|
|
|
|
self._client = client
|
|
|
|
|
|
|
|
def get_uri(self):
|
|
|
|
return self.uri
|
|
|
|
|
2008-05-19 20:03:00 +00:00
|
|
|
def is_mutable(self):
|
|
|
|
return False
|
|
|
|
|
2007-12-03 21:52:42 +00:00
|
|
|
def is_readonly(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_readonly_uri(self):
|
|
|
|
return self.uri
|
|
|
|
|
|
|
|
def get_size(self):
|
2008-07-17 23:47:09 +00:00
|
|
|
return self.u.get_size()
|
2007-12-03 21:52:42 +00:00
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
return hash((self.__class__, self.uri))
|
|
|
|
def __cmp__(self, them):
|
|
|
|
if cmp(type(self), type(them)):
|
|
|
|
return cmp(type(self), type(them))
|
|
|
|
if cmp(self.__class__, them.__class__):
|
|
|
|
return cmp(self.__class__, them.__class__)
|
|
|
|
return cmp(self.uri, them.uri)
|
|
|
|
|
|
|
|
def get_verifier(self):
|
2008-07-17 23:47:09 +00:00
|
|
|
return self.u.get_verifier()
|
2007-12-03 21:52:42 +00:00
|
|
|
|
2008-08-12 23:14:07 +00:00
|
|
|
def get_storage_index(self):
|
|
|
|
return self.u.storage_index
|
|
|
|
|
2008-09-07 19:44:56 +00:00
|
|
|
def check(self, verify=False):
|
2008-07-17 23:47:09 +00:00
|
|
|
storage_index = self.u.storage_index
|
|
|
|
k = self.u.needed_shares
|
|
|
|
N = self.u.total_shares
|
|
|
|
size = self.u.size
|
|
|
|
ueb_hash = self.u.uri_extension_hash
|
2008-07-16 00:23:25 +00:00
|
|
|
if verify:
|
2008-07-17 23:47:09 +00:00
|
|
|
v = self.verifier_class(self._client,
|
|
|
|
storage_index, k, N, size, ueb_hash)
|
2008-07-16 00:23:25 +00:00
|
|
|
else:
|
2008-07-17 23:47:09 +00:00
|
|
|
v = self.checker_class(self._client, storage_index, k, N)
|
|
|
|
return v.start()
|
2007-12-03 21:52:42 +00:00
|
|
|
|
2008-09-07 19:44:56 +00:00
|
|
|
def check_and_repair(self, verify=False):
|
2008-09-09 23:34:49 +00:00
|
|
|
# this is a stub, to allow the deep-check tests to pass.
|
|
|
|
#raise NotImplementedError("not implemented yet")
|
|
|
|
from allmydata.checker_results import CheckAndRepairResults
|
|
|
|
cr = CheckAndRepairResults(self.u.storage_index)
|
|
|
|
d = self.check(verify)
|
|
|
|
def _done(r):
|
|
|
|
cr.pre_repair_results = cr.post_repair_results = r
|
|
|
|
cr.repair_attempted = False
|
|
|
|
return cr
|
|
|
|
d.addCallback(_done)
|
|
|
|
return d
|
2008-09-07 19:44:56 +00:00
|
|
|
|
2007-12-03 21:52:42 +00:00
|
|
|
def download(self, target):
|
|
|
|
downloader = self._client.getServiceNamed("downloader")
|
|
|
|
return downloader.download(self.uri, target)
|
|
|
|
|
|
|
|
def download_to_data(self):
|
|
|
|
downloader = self._client.getServiceNamed("downloader")
|
|
|
|
return downloader.download_to_data(self.uri)
|
|
|
|
|
2007-12-04 04:37:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LiteralFileNode:
|
2008-07-16 00:23:25 +00:00
|
|
|
implements(IFileNode, ICheckable)
|
2007-12-04 04:37:54 +00:00
|
|
|
|
|
|
|
def __init__(self, my_uri, client):
|
|
|
|
u = IFileURI(my_uri)
|
|
|
|
assert isinstance(u, uri.LiteralFileURI)
|
|
|
|
self.uri = u.to_string()
|
|
|
|
self._client = client
|
|
|
|
|
|
|
|
def get_uri(self):
|
|
|
|
return self.uri
|
|
|
|
|
2008-05-19 20:03:00 +00:00
|
|
|
def is_mutable(self):
|
|
|
|
return False
|
|
|
|
|
2007-12-04 04:37:54 +00:00
|
|
|
def is_readonly(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_readonly_uri(self):
|
|
|
|
return self.uri
|
|
|
|
|
|
|
|
def get_size(self):
|
|
|
|
return len(IURI(self.uri).data)
|
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
return hash((self.__class__, self.uri))
|
|
|
|
def __cmp__(self, them):
|
|
|
|
if cmp(type(self), type(them)):
|
|
|
|
return cmp(type(self), type(them))
|
|
|
|
if cmp(self.__class__, them.__class__):
|
|
|
|
return cmp(self.__class__, them.__class__)
|
|
|
|
return cmp(self.uri, them.uri)
|
|
|
|
|
|
|
|
def get_verifier(self):
|
|
|
|
return None
|
|
|
|
|
2008-08-12 23:14:07 +00:00
|
|
|
def get_storage_index(self):
|
|
|
|
return None
|
|
|
|
|
2008-09-09 23:34:49 +00:00
|
|
|
def check(self, verify=False):
|
2008-09-07 19:44:56 +00:00
|
|
|
# neither verify= nor repair= affect LIT files, and the check returns
|
|
|
|
# no results.
|
|
|
|
return defer.succeed(None)
|
2007-12-04 04:37:54 +00:00
|
|
|
|
2008-09-09 23:34:49 +00:00
|
|
|
def check_and_repair(self, verify=False):
|
|
|
|
return defer.succeed(None)
|
|
|
|
|
2007-12-04 04:37:54 +00:00
|
|
|
def download(self, target):
|
2008-07-16 00:23:25 +00:00
|
|
|
# note that this does not update the stats_provider
|
2007-12-04 04:37:54 +00:00
|
|
|
data = IURI(self.uri).data
|
|
|
|
target.open(len(data))
|
|
|
|
target.write(data)
|
|
|
|
target.close()
|
|
|
|
return defer.maybeDeferred(target.finish)
|
|
|
|
|
|
|
|
def download_to_data(self):
|
|
|
|
data = IURI(self.uri).data
|
|
|
|
return defer.succeed(data)
|