def recover_2d(self, fname, x, y): """ recover data drives (x and y) :param fname: data name :param x: corrupted data disk index :param y: corrupted data disk index :return: """ assert 0 <= x < self.N - 2 assert 0 <= y < self.N - 2 assert x != y byte_ndarray = self._read_n(fname, self.N, exclude=[x, y]) DD = byte_ndarray[:-2] P = byte_ndarray[-2:-1] Q = byte_ndarray[-1:] # Pxy Pxy = utils.gen_p(DD, ndim=2) # Qxy Qxy = utils.gen_q(DD, ndim=2) # Axy, Bxy A = self.gf.Axy(x, y) B = self.gf.Bxy(x, y) # Dx first = utils.gf_a_multiply_list(A, utils.gf_1darray_add(P, Pxy)) second = utils.gf_a_multiply_list(B, utils.gf_1darray_add(Q, Qxy)) Dx = utils.gf_1darray_add(np.array(first, dtype=config.BYTE_TYPE), np.array(second, dtype=config.BYTE_TYPE)) Dx_content = self._1darray_to_str(Dx) x_fpath = self.get_real_name(x, fname) utils.write_content(x_fpath, Dx_content) # Dy Dy = utils.gf_1darray_add(P ^ Pxy, Dx) Dy_content = self._1darray_to_str(Dy) y_fpath = self.get_real_name(y, fname) utils.write_content(y_fpath, Dy_content)
def recover_d_p(self, fname, index): """ recover data drive (index) and 'p' drive :param fname: data name :param index: data disk index :return: """ assert 0 <= index < self.N - 2 byte_ndarray = self._read_n(fname, self.N, exclude=index) DD = byte_ndarray[:-2] Q = byte_ndarray[-1:] # Dx Qx = utils.gen_q(DD, ndim=2) g_x_inv = self.gf.generator[(self.gf.circle - index) % self.gf.circle] ### _add_list = utils.gf_1darray_add(Q, Qx) Dx_list = utils.gf_a_multiply_list(g_x_inv, _add_list) ### Dx_content = ''.join(chr(i) for i in Dx_list) x_fpath = self.get_real_name(index, fname) utils.write_content(x_fpath, Dx_content) # p Dx = np.array(Dx_list, ndmin=2) assert Dx.shape[1] == byte_ndarray.shape[1] # update firstly DD[index] = Dx P = utils.gen_p(DD, ndim=1) assert P.shape[0] == byte_ndarray.shape[1] # do not need to update DD P_content = self._1darray_to_str(P) P_path = self.get_real_name(self.N - 2, fname) utils.write_content(P_path, P_content)
def recover_2d(self, fname, x, y): """ recover data drives (x and y) :param fname: data name :param x: corrupted data disk index :param y: corrupted data disk index :return: """ assert 0 <= x < self.N - 2 assert 0 <= y < self.N - 2 assert x != y byte_ndarray = self._read_n(fname, self.N, exclude=[x, y]) DD = byte_ndarray[:-2] P = byte_ndarray[-2:-1] Q = byte_ndarray[-1:] # Pxy Pxy = utils.gen_p(DD, ndim=2) # Qxy Qxy = utils.gen_q(DD, ndim=2) # Axy, Bxy A = self.gf.Axy(x, y) B = self.gf.Bxy(x, y) # Dx first = utils.gf_a_multiply_list(A, utils.gf_1darray_add(P, Pxy)) second = utils.gf_a_multiply_list(B, utils.gf_1darray_add(Q, Qxy)) Dx = utils.gf_1darray_add( np.array( first, dtype=config.BYTE_TYPE), np.array( second, dtype=config.BYTE_TYPE)) Dx_content = self._1darray_to_str(Dx) x_fpath = self.get_real_name(x, fname) utils.write_content(x_fpath, Dx_content) # Dy Dy = utils.gf_1darray_add(P ^ Pxy, Dx) Dy_content = self._1darray_to_str(Dy) y_fpath = self.get_real_name(y, fname) utils.write_content(y_fpath, Dy_content)