def corrupt(res, s, offset, shnums_to_corrupt=None, offset_offset=0): # if shnums_to_corrupt is None, corrupt all shares. Otherwise it is a # list of shnums to corrupt. ds = [] for peerid in s._peers: shares = s._peers[peerid] for shnum in shares: if (shnums_to_corrupt is not None and shnum not in shnums_to_corrupt): continue data = shares[shnum] # We're feeding the reader all of the share data, so it # won't need to use the rref that we didn't provide, nor the # storage index that we didn't provide. We do this because # the reader will work for both MDMF and SDMF. reader = MDMFSlotReadProxy(None, None, shnum, data) # We need to get the offsets for the next part. d = reader.get_verinfo() def _do_corruption(verinfo, data, shnum, shares): (seqnum, root_hash, IV, segsize, datalen, k, n, prefix, o) = verinfo if isinstance(offset, tuple): offset1, offset2 = offset else: offset1 = offset offset2 = 0 if offset1 == "pubkey" and IV: real_offset = 107 elif offset1 in o: real_offset = o[offset1] else: real_offset = offset1 real_offset = int(real_offset) + offset2 + offset_offset assert isinstance(real_offset, int), offset if offset1 == 0: # verbyte f = add_two else: f = flip_bit shares[shnum] = f(data, real_offset) d.addCallback(_do_corruption, data, shnum, shares) ds.append(d) dl = defer.DeferredList(ds) dl.addCallback(lambda ignored: res) return dl