Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #188 from ro-ket/ro-ket-issue-87
Browse files Browse the repository at this point in the history
 Add support for null checksum type. Fixes #87
  • Loading branch information
Wouter de Bie committed Jan 25, 2016
2 parents f4ec5cb + 5eec5d2 commit 561a013
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions snakebite/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,9 @@ def readBlock(self, length, pool_id, block_id, generation_stamp, offset, block_t
checksum_type = block_op_response.readOpChecksumInfo.checksum.type
bytes_per_chunk = block_op_response.readOpChecksumInfo.checksum.bytesPerChecksum
log.debug("Checksum type: %s, bytesPerChecksum: %s" % (checksum_type, bytes_per_chunk))
if checksum_type in [self.CHECKSUM_CRC32C, self.CHECKSUM_CRC32]:
if checksum_type in [self.CHECKSUM_NULL]:
checksum_len = 0
elif checksum_type in [self.CHECKSUM_CRC32C, self.CHECKSUM_CRC32]:
checksum_len = 4
else:
raise Exception("Checksum type %s not implemented" % checksum_type)
Expand Down Expand Up @@ -606,7 +608,7 @@ def readBlock(self, length, pool_id, block_id, generation_stamp, offset, block_t
byte_stream.reset()

# Collect checksums
if check_crc:
if check_crc and checksum_type != self.CHECKSUM_NULL:
checksums = []
for _ in xrange(0, chunks_per_packet):
checksum = self._read_bytes(checksum_len)
Expand All @@ -627,7 +629,7 @@ def readBlock(self, length, pool_id, block_id, generation_stamp, offset, block_t
log.debug("Reading chunk %s in load %s:", j, i)
bytes_to_read = min(bytes_per_chunk, data_len - read_on_packet)
chunk = self._read_bytes(bytes_to_read)
if check_crc:
if check_crc and checksum_type != self.CHECKSUM_NULL:
checksum_index = i * chunks_per_load + j
if checksum_index < len(checksums) and crc(chunk) != checksums[checksum_index]:
raise Exception("Checksum doesn't match")
Expand Down

0 comments on commit 561a013

Please sign in to comment.