From: Brian Warner Date: Wed, 28 Mar 2007 20:30:17 +0000 (-0700) Subject: encode_new.py: rearrange methods into the order in which they should be called X-Git-Url: https://git.rkrishnan.org/architecture.txt?a=commitdiff_plain;h=6f718d72a9a920dbe3a029508522938569f93b02;p=tahoe-lafs%2Ftahoe-lafs.git encode_new.py: rearrange methods into the order in which they should be called --- diff --git a/src/allmydata/encode_new.py b/src/allmydata/encode_new.py index 88ca52af..5b8a784c 100644 --- a/src/allmydata/encode_new.py +++ b/src/allmydata/encode_new.py @@ -92,27 +92,14 @@ class Encoder(object): self.segment_size = min(2*MiB, self.file_size) self.num_segments = mathutil.div_ceil(self.file_size, self.segment_size) - def setup_encoder(self): - self.encoder = CRSEncoder() - self.encoder.set_params(self.segment_size, self.required_shares, - self.num_shares) - def get_reservation_size(self): self.num_shares = 100 self.share_size = mathutil.div_ceil(self.file_size, self.required_shares) overhead = self.compute_overhead() return self.share_size + overhead - def setup_encryption(self): - self.key = "\x00"*16 - self.cryptor = AES.new(key=self.key, mode=AES.MODE_CTR, - counterstart="\x00"*16) - self.segment_num = 0 - self.subshare_hashes = [[] for x in range(self.num_shares)] - # subshare_hashes[i] is a list that will be accumulated and then send - # to landlord[i]. This list contains a hash of each segment_share - # that we sent to that landlord. - self.share_root_hashes = [None] * self.num_shares + def set_shareholders(self, landlords): + self.landlords = landlords.copy() def start(self): self.setup_encryption() @@ -126,6 +113,22 @@ class Encoder(object): d.addCallback(lambda res: self.done()) return d + def setup_encryption(self): + self.key = "\x00"*16 + self.cryptor = AES.new(key=self.key, mode=AES.MODE_CTR, + counterstart="\x00"*16) + self.segment_num = 0 + self.subshare_hashes = [[] for x in range(self.num_shares)] + # subshare_hashes[i] is a list that will be accumulated and then send + # to landlord[i]. This list contains a hash of each segment_share + # that we sent to that landlord. + self.share_root_hashes = [None] * self.num_shares + + def setup_encoder(self): + self.encoder = CRSEncoder() + self.encoder.set_params(self.segment_size, self.required_shares, + self.num_shares) + def do_segment(self, segnum): chunks = [] # the ICodecEncoder API wants to receive a total of self.segment_size @@ -172,9 +175,6 @@ class Encoder(object): # return self.send(shareid, "write", subshare, offset) return self.send(shareid, "put_subshare", segment_num, subshare) - def set_landlords(self, landlords): - self.landlords = landlords.copy() - def send(self, shareid, methname, *args, **kwargs): ll = self.landlords[shareid] return ll.callRemote(methname, *args, **kwargs)