mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-05-02 09:03:00 +00:00
download.py: refactor get-thingA-from-somebody to reuse the logic for other things
This commit is contained in:
parent
dcf5abb51c
commit
fae4e8f9a3
@ -301,27 +301,37 @@ class FileDownloader:
|
|||||||
# assert isinstance(vb, ValidatedBucket), \
|
# assert isinstance(vb, ValidatedBucket), \
|
||||||
# "vb is %s but should be a ValidatedBucket" % (vb,)
|
# "vb is %s but should be a ValidatedBucket" % (vb,)
|
||||||
|
|
||||||
def _obtain_thingA(self, ignored=None):
|
def _obtain_thingA(self, ignored):
|
||||||
# all shareholders are supposed to have a copy of thingA, and all are
|
# all shareholders are supposed to have a copy of thingA, and all are
|
||||||
# supposed to be identical. We compute the hash of the data that
|
# supposed to be identical. We compute the hash of the data that
|
||||||
# comes back, and compare it against the version in our URI. If they
|
# comes back, and compare it against the version in our URI. If they
|
||||||
# don't match, ignore their data and try someone else.
|
# don't match, ignore their data and try someone else.
|
||||||
if not self._thingA_sources:
|
def _validate(proposal, bucket):
|
||||||
raise NotEnoughPeersError("ran out of peers while fetching thingA")
|
h = hashtree.thingA_hash(proposal)
|
||||||
bucket = self._thingA_sources.pop()
|
|
||||||
d = bucket.callRemote("get_thingA")
|
|
||||||
def _got(thingA):
|
|
||||||
h = hashtree.thingA_hash(thingA)
|
|
||||||
if h != self._thingA_hash:
|
if h != self._thingA_hash:
|
||||||
msg = ("The copy of thingA we received from %s was bad" %
|
msg = ("The copy of thingA we received from %s was bad" %
|
||||||
bucket)
|
bucket)
|
||||||
raise BadThingAHashValue(msg)
|
raise BadThingAHashValue(msg)
|
||||||
return bencode.bdecode(thingA)
|
return bencode.bdecode(proposal)
|
||||||
d.addCallback(_got)
|
return self._obtain_validated_thing(None,
|
||||||
|
self._thingA_sources,
|
||||||
|
"thingA",
|
||||||
|
"get_thingA", (), _validate)
|
||||||
|
|
||||||
|
def _obtain_validated_thing(self, ignored, sources, name, methname, args,
|
||||||
|
validatorfunc):
|
||||||
|
if not sources:
|
||||||
|
raise NotEnoughPeersError("ran out of peers while fetching %s" %
|
||||||
|
name)
|
||||||
|
bucket = sources[0]
|
||||||
|
sources = sources[1:]
|
||||||
|
d = bucket.callRemote(methname, *args)
|
||||||
|
d.addCallback(validatorfunc, bucket)
|
||||||
def _bad(f):
|
def _bad(f):
|
||||||
log.msg("thingA from vbucket %s failed: %s" % (bucket, f)) # WEIRD
|
log.msg("%s from vbucket %s failed: %s" % (name, bucket, f)) # WEIRD
|
||||||
# try again with a different one
|
# try again with a different one
|
||||||
return self._obtain_thingA()
|
return self._obtain_validated_thing(None, sources, name,
|
||||||
|
methname, args, validatorfunc)
|
||||||
d.addErrback(_bad)
|
d.addErrback(_bad)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user