Class DigestManager
- java.lang.Object
-
- org.apache.bookkeeper.proto.checksum.DigestManager
-
- Direct Known Subclasses:
CRC32CDigestManager
,CRC32DigestManager
,DummyDigestManager
,MacDigestManager
public abstract class DigestManager extends java.lang.Object
This class takes an entry, attaches a digest to it and packages it with relevant data so that it can be shipped to the bookie. On the return side, it also gets a packet, checks that the digest matches, and extracts the original entry for the packet. Currently 3 types of digests are supported: MAC (based on SHA-1) and CRC32 and CRC32C.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DigestManager.RecoveryData
A representation of RecoveryData.
-
Field Summary
Fields Modifier and Type Field Description static int
LAC_METADATA_LENGTH
(package private) long
ledgerId
(package private) int
macCodeLength
static int
METADATA_LENGTH
(package private) boolean
useV2Protocol
-
Constructor Summary
Constructors Constructor Description DigestManager(long ledgerId, boolean useV2Protocol, io.netty.buffer.ByteBufAllocator allocator)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract boolean
acceptsMemoryAddressBuffer()
io.netty.util.ReferenceCounted
computeDigestAndPackageForSending(long entryId, long lastAddConfirmed, long length, io.netty.buffer.ByteBuf data, byte[] masterKey, int flags)
Computes the digest for an entry and put bytes together for sending.ByteBufList
computeDigestAndPackageForSendingLac(long lac)
Computes the digest for writeLac for sending.static byte[]
generateMasterKey(byte[] password)
(package private) abstract int
getMacCodeLength()
static DigestManager
instantiate(long ledgerId, byte[] passwd, DataFormats.LedgerMetadataFormat.DigestType digestType, io.netty.buffer.ByteBufAllocator allocator, boolean useV2Protocol)
(package private) abstract int
internalUpdate(int digest, byte[] buffer, int offset, int len)
(package private) abstract int
internalUpdate(int digest, io.netty.buffer.ByteBuf buffer, int offset, int len)
(package private) abstract boolean
isInt32Digest()
(package private) abstract void
populateValueAndReset(int digest, io.netty.buffer.ByteBuf buffer)
(package private) int
update(int digest, io.netty.buffer.ByteBuf buffer, int offset, int len)
io.netty.buffer.ByteBuf
verifyDigestAndReturnData(long entryId, io.netty.buffer.ByteBuf dataReceived)
Verify that the digest matches and returns the data in the entry.long
verifyDigestAndReturnLac(io.netty.buffer.ByteBuf dataReceived)
DigestManager.RecoveryData
verifyDigestAndReturnLastConfirmed(io.netty.buffer.ByteBuf dataReceived)
-
-
-
Field Detail
-
METADATA_LENGTH
public static final int METADATA_LENGTH
- See Also:
- Constant Field Values
-
LAC_METADATA_LENGTH
public static final int LAC_METADATA_LENGTH
- See Also:
- Constant Field Values
-
ledgerId
final long ledgerId
-
useV2Protocol
final boolean useV2Protocol
-
macCodeLength
final int macCodeLength
-
-
Method Detail
-
getMacCodeLength
abstract int getMacCodeLength()
-
internalUpdate
abstract int internalUpdate(int digest, io.netty.buffer.ByteBuf buffer, int offset, int len)
-
internalUpdate
abstract int internalUpdate(int digest, byte[] buffer, int offset, int len)
-
update
final int update(int digest, io.netty.buffer.ByteBuf buffer, int offset, int len)
-
populateValueAndReset
abstract void populateValueAndReset(int digest, io.netty.buffer.ByteBuf buffer)
-
isInt32Digest
abstract boolean isInt32Digest()
-
instantiate
public static DigestManager instantiate(long ledgerId, byte[] passwd, DataFormats.LedgerMetadataFormat.DigestType digestType, io.netty.buffer.ByteBufAllocator allocator, boolean useV2Protocol) throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
-
generateMasterKey
public static byte[] generateMasterKey(byte[] password) throws java.security.NoSuchAlgorithmException
- Throws:
java.security.NoSuchAlgorithmException
-
computeDigestAndPackageForSending
public io.netty.util.ReferenceCounted computeDigestAndPackageForSending(long entryId, long lastAddConfirmed, long length, io.netty.buffer.ByteBuf data, byte[] masterKey, int flags)
Computes the digest for an entry and put bytes together for sending.- Parameters:
entryId
-lastAddConfirmed
-length
-data
-- Returns:
-
computeDigestAndPackageForSendingLac
public ByteBufList computeDigestAndPackageForSendingLac(long lac)
Computes the digest for writeLac for sending.- Parameters:
lac
-- Returns:
-
verifyDigestAndReturnLac
public long verifyDigestAndReturnLac(io.netty.buffer.ByteBuf dataReceived) throws BKException.BKDigestMatchException
-
verifyDigestAndReturnData
public io.netty.buffer.ByteBuf verifyDigestAndReturnData(long entryId, io.netty.buffer.ByteBuf dataReceived) throws BKException.BKDigestMatchException
Verify that the digest matches and returns the data in the entry.- Parameters:
entryId
-dataReceived
-- Returns:
- Throws:
BKException.BKDigestMatchException
-
verifyDigestAndReturnLastConfirmed
public DigestManager.RecoveryData verifyDigestAndReturnLastConfirmed(io.netty.buffer.ByteBuf dataReceived) throws BKException.BKDigestMatchException
-
acceptsMemoryAddressBuffer
abstract boolean acceptsMemoryAddressBuffer()
-
-