From: Brian Warner Date: Mon, 22 Oct 2007 23:19:18 +0000 (-0700) Subject: checker.py: rearrange classes a little bit X-Git-Tag: allmydata-tahoe-0.7.0~358 X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html/$rel_link?a=commitdiff_plain;h=81c818f90c6b219786efad73e3a7580192eabbeb;p=tahoe-lafs%2Ftahoe-lafs.git checker.py: rearrange classes a little bit --- diff --git a/src/allmydata/checker.py b/src/allmydata/checker.py index 08c2c57b..2caef9b6 100644 --- a/src/allmydata/checker.py +++ b/src/allmydata/checker.py @@ -93,42 +93,6 @@ class SimpleDirnodeChecker: log.err(f) return False -class Checker(service.MultiService): - """I am a service that helps perform file checks. - """ - name = "checker" - - def check(self, uri_to_check): - uri_to_check = IVerifierURI(uri_to_check) - if uri_to_check is None: - return defer.succeed(True) - elif isinstance(uri_to_check, uri.CHKFileVerifierURI): - peer_getter = self.parent.get_permuted_peers - c = SimpleCHKFileChecker(peer_getter, uri_to_check) - return c.check() - elif isinstance(uri_to_check, uri.DirnodeVerifierURI): - tub = self.parent.tub - c = SimpleDirnodeChecker(tub) - return c.check(uri_to_check) - else: - raise ValueError("I don't know how to check '%s'" % (uri_to_check,)) - - def verify(self, uri_to_verify): - uri_to_verify = IVerifierURI(uri_to_verify) - if uri_to_verify is None: - return defer.succeed(True) - elif isinstance(uri_to_verify, uri.CHKFileVerifierURI): - v = SimpleCHKFileVerifier(self.parent, uri_to_verify) - return v.start() - elif isinstance(uri_to_verify, uri.DirnodeVerifierURI): - # for dirnodes, checking and verifying are currently equivalent - tub = self.parent.tub - c = SimpleDirnodeChecker(tub) - return c.check(uri_to_verify) - else: - raise ValueError("I don't know how to verify '%s'" % - (uri_to_verify,)) - class VerifyingOutput: def __init__(self, total_length): self._crypttext_hasher = hashutil.crypttext_hasher() @@ -210,3 +174,40 @@ class SimpleCHKFileVerifier(download.FileDownloader): d.addCallback(self._download_all_segments) d.addCallback(self._done) return d + + +class Checker(service.MultiService): + """I am a service that helps perform file checks. + """ + name = "checker" + + def check(self, uri_to_check): + uri_to_check = IVerifierURI(uri_to_check) + if uri_to_check is None: + return defer.succeed(True) + elif isinstance(uri_to_check, uri.CHKFileVerifierURI): + peer_getter = self.parent.get_permuted_peers + c = SimpleCHKFileChecker(peer_getter, uri_to_check) + return c.check() + elif isinstance(uri_to_check, uri.DirnodeVerifierURI): + tub = self.parent.tub + c = SimpleDirnodeChecker(tub) + return c.check(uri_to_check) + else: + raise ValueError("I don't know how to check '%s'" % (uri_to_check,)) + + def verify(self, uri_to_verify): + uri_to_verify = IVerifierURI(uri_to_verify) + if uri_to_verify is None: + return defer.succeed(True) + elif isinstance(uri_to_verify, uri.CHKFileVerifierURI): + v = SimpleCHKFileVerifier(self.parent, uri_to_verify) + return v.start() + elif isinstance(uri_to_verify, uri.DirnodeVerifierURI): + # for dirnodes, checking and verifying are currently equivalent + tub = self.parent.tub + c = SimpleDirnodeChecker(tub) + return c.check(uri_to_verify) + else: + raise ValueError("I don't know how to verify '%s'" % + (uri_to_verify,))