encode_new.py: rearrange methods into the order in which they should be called

This commit is contained in:
Brian Warner 2007-03-28 13:30:17 -07:00
parent 74d0839980
commit 6f718d72a9

View File

@ -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)