Exemple #1
0
def getStrongMDSPropertyDegree(repairNodeno, nativeBlockNum, parityBlockNum, checkNum, enc_matrix):
    '''Get strong MDS property degree.'''

    currentStrongMDSPropertyDegree = 0
    survivalcoeffvectorset = []
    flag = 0
    for i in range(parityBlockNum):
    #get coeff vectors of survival parity blocks
        if int(i/2)!= repairNodeno:
            survivalcoeffvectorset.append(CoeffVector(nativeBlockNum))
            for j in range(nativeBlockNum):
                survivalcoeffvectorset[i - flag*2].coeff_[j] = enc_matrix[i][j]
            survivalcoeffvectorset[i - flag*2].first()  
        else:
            flag =1

    s = 0
    for i in range(parityBlockNum-2):
        for j in range(parityBlockNum-2):
            if i<j:
                checkmatrix = CoeffMatrix(nativeBlockNum)
                for k in range (parityBlockNum-2):
                    if k!=i and k!=j:
                        checkmatrix.addcoeffvector(survivalcoeffvectorset[k].copy())
                if checkmatrix.rank_ == nativeBlockNum:
                    currentStrongMDSPropertyDegree += 1
                s += 1
    return currentStrongMDSPropertyDegree
Exemple #2
0
def getStrongMDSPropertyDegree(repairNodeno, nativeBlockNum, parityBlockNum,
                               checkNum, enc_matrix):
    '''Get strong MDS property degree.'''

    currentStrongMDSPropertyDegree = 0
    survivalcoeffvectorset = []
    flag = 0
    for i in range(parityBlockNum):
        #get coeff vectors of survival parity blocks
        if int(i / 2) != repairNodeno:
            survivalcoeffvectorset.append(CoeffVector(nativeBlockNum))
            for j in range(nativeBlockNum):
                survivalcoeffvectorset[i -
                                       flag * 2].coeff_[j] = enc_matrix[i][j]
            survivalcoeffvectorset[i - flag * 2].first()
        else:
            flag = 1

    s = 0
    for i in range(parityBlockNum - 2):
        for j in range(parityBlockNum - 2):
            if i < j:
                checkmatrix = CoeffMatrix(nativeBlockNum)
                for k in range(parityBlockNum - 2):
                    if k != i and k != j:
                        checkmatrix.addcoeffvector(
                            survivalcoeffvectorset[k].copy())
                if checkmatrix.rank_ == nativeBlockNum:
                    currentStrongMDSPropertyDegree += 1
                s += 1
    return currentStrongMDSPropertyDegree
Exemple #3
0
def decode(n, k, src, blocknums, parityCoeff, dest, filesize, setting):
    '''Decode chunk files to dest file.'''

    ## special handling for 0B files
    if filesize <= 0:
        open(dest,'wb').close()
        return

    cv_temp=[]
    nativeBlockNum = getNativeBlockNum(n, k)
    parityBlockNum = getParityBlockNum(n, k)
    enc_matrix = [[GF256int(0) for col in range(nativeBlockNum)] for row in range(parityBlockNum)]
    dec_matrix = [[GF256int(0) for col in range(nativeBlockNum)] for row in range(nativeBlockNum)]
    rev_matrix = [[GF256int(0) for col in range(nativeBlockNum)] for row in range(nativeBlockNum)]
    gj_matrix = [[GF256int(0) for col in range(nativeBlockNum*2)] for row in range(nativeBlockNum)]

    ## generate the encoding matrix
    counter = 0
    for i in range(parityBlockNum):
        for j in range(nativeBlockNum):
            enc_matrix[i][j] = GF256int(parityCoeff[counter])
            counter += 1

    cm1 = CoeffMatrix(nativeBlockNum)
    for i in range(parityBlockNum):
        cv_temp.append(CoeffVector(nativeBlockNum))
        for j in range(nativeBlockNum):
            cv_temp[i].coeff_[j] = enc_matrix[i][j]
        cv_temp[i].first()
        cm1.addcoeffvector(cv_temp[i])

    ## generate the decoding matrix
    i=0
    for selectChunkNo in blocknums:
        for j in range(nativeBlockNum):
            dec_matrix[i][j]=enc_matrix[selectChunkNo][j]
        i += 1

    ## initialize the reverse matrix
    for i in range(nativeBlockNum):
        for j in range(nativeBlockNum):
            if j==i:
                rev_matrix[i][j]= GF256int(1)

    ## initialize the Gauss-Jordan matrix = [decoding,reverse]
    for i in range(nativeBlockNum):
        for j in range(nativeBlockNum*2):
            if j<nativeBlockNum:
                gj_matrix[i][j]= dec_matrix[i][j]
            else:
                gj_matrix[i][j]= rev_matrix[i][j-nativeBlockNum]

    reversematrix(n, k, gj_matrix)

    for i in range(nativeBlockNum):
        for j in range(nativeBlockNum):
            dec_matrix[i][j] = gj_matrix[i][j+nativeBlockNum]

    ##generate decode data chunks
    selectchunk=[]
    for filename in src:
        infile = open(filename,'rb')
        selectchunk.append(infile.read())
        infile.close()
    chunksize = os.path.getsize(src[0])
    indatalist = ''.join(selectchunk)

    ##rebuild the original chunks
    parityCoeff_temp = ''.join([chr(dec_matrix[i][j]) \
                                for i in range(nativeBlockNum) \
                                for j in range(nativeBlockNum)])
    outdatalist = codings.clibfmsr.clibfmsr.decodeComputation(indatalist, \
                           parityCoeff_temp, nativeBlockNum, chunksize)

    outfile = open(dest,'wb')
    writelen = 1048576
    writenext = 0
    for i in range(0,filesize-writelen,writelen):
        writenext = i+writelen
        outfile.write(outdatalist[i:writenext])
    outfile.write(outdatalist[writenext:filesize])
    outfile.close()
Exemple #4
0
def decode(n, k, src, blocknums, parityCoeff, dest, filesize, setting):
    '''Decode chunk files to dest file.'''

    ## special handling for 0B files
    if filesize <= 0:
        open(dest, 'wb').close()
        return

    cv_temp = []
    nativeBlockNum = getNativeBlockNum(n, k)
    parityBlockNum = getParityBlockNum(n, k)
    enc_matrix = [[GF256int(0) for col in range(nativeBlockNum)]
                  for row in range(parityBlockNum)]
    dec_matrix = [[GF256int(0) for col in range(nativeBlockNum)]
                  for row in range(nativeBlockNum)]
    rev_matrix = [[GF256int(0) for col in range(nativeBlockNum)]
                  for row in range(nativeBlockNum)]
    gj_matrix = [[GF256int(0) for col in range(nativeBlockNum * 2)]
                 for row in range(nativeBlockNum)]

    ## generate the encoding matrix
    counter = 0
    for i in range(parityBlockNum):
        for j in range(nativeBlockNum):
            enc_matrix[i][j] = GF256int(parityCoeff[counter])
            counter += 1

    cm1 = CoeffMatrix(nativeBlockNum)
    for i in range(parityBlockNum):
        cv_temp.append(CoeffVector(nativeBlockNum))
        for j in range(nativeBlockNum):
            cv_temp[i].coeff_[j] = enc_matrix[i][j]
        cv_temp[i].first()
        cm1.addcoeffvector(cv_temp[i])

    ## generate the decoding matrix
    i = 0
    for selectChunkNo in blocknums:
        for j in range(nativeBlockNum):
            dec_matrix[i][j] = enc_matrix[selectChunkNo][j]
        i += 1

    ## initialize the reverse matrix
    for i in range(nativeBlockNum):
        for j in range(nativeBlockNum):
            if j == i:
                rev_matrix[i][j] = GF256int(1)

    ## initialize the Gauss-Jordan matrix = [decoding,reverse]
    for i in range(nativeBlockNum):
        for j in range(nativeBlockNum * 2):
            if j < nativeBlockNum:
                gj_matrix[i][j] = dec_matrix[i][j]
            else:
                gj_matrix[i][j] = rev_matrix[i][j - nativeBlockNum]

    reversematrix(n, k, gj_matrix)

    for i in range(nativeBlockNum):
        for j in range(nativeBlockNum):
            dec_matrix[i][j] = gj_matrix[i][j + nativeBlockNum]

    ##generate decode data chunks
    selectchunk = []
    for filename in src:
        infile = open(filename, 'rb')
        selectchunk.append(infile.read())
        infile.close()
    chunksize = os.path.getsize(src[0])
    indatalist = ''.join(selectchunk)

    ##rebuild the original chunks
    parityCoeff_temp = ''.join([chr(dec_matrix[i][j]) \
                                for i in range(nativeBlockNum) \
                                for j in range(nativeBlockNum)])
    outdatalist = codings.clibfmsr.clibfmsr.decodeComputation(indatalist, \
                           parityCoeff_temp, nativeBlockNum, chunksize)

    outfile = open(dest, 'wb')
    writelen = 1048576
    writenext = 0
    for i in range(0, filesize - writelen, writelen):
        writenext = i + writelen
        outfile.write(outdatalist[i:writenext])
    outfile.write(outdatalist[writenext:filesize])
    outfile.close()