Class 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.
    • Field Detail

      • ledgerId

        final long ledgerId
      • useV2Protocol

        final boolean useV2Protocol
      • macCodeLength

        final int macCodeLength
    • Constructor Detail

      • DigestManager

        public DigestManager​(long ledgerId,
                             boolean useV2Protocol,
                             io.netty.buffer.ByteBufAllocator allocator)
    • 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:
      • 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
      • acceptsMemoryAddressBuffer

        abstract boolean acceptsMemoryAddressBuffer()