Re: [freenet-dev] [freenet-cvs] r19733 - branches/saltedhash…

Top Page
Author: Matthew Toseland
Date:  
To: devl
Subject: Re: [freenet-dev] [freenet-cvs] r19733 - branches/saltedhashstore/freenet/src/freenet/store
Delete this message
Reply to this message
gpg: Signature made Fri May 9 22:03:24 2008 UTC using DSA key ID E43DA450
gpg: Good signature from "Matthew John Toseland <toad@amphibian.dyndns.org>"
On Sunday 04 May 2008 14:11, you wrote:
> Author: j16sdiz
> Date: 2008-05-04 13:11:55 +0000 (Sun, 04 May 2008)
> New Revision: 19733
>
> Added:
>

branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
> Log:
> SaltedHashFreenetStore basic function (without locking/resizing)
>
>
> Added:

branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java
> ===================================================================
> ---

branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java    
(rev 0)
> +++

branches/saltedhashstore/freenet/src/freenet/store/SaltedHashFreenetStore.java    
2008-05-04 13:11:55 UTC (rev 19733)
> +
> +        public StorableBlock getStorableBlock(byte[] routingKey, byte[] fullKey)

throws KeyVerifyException {
> +            if (!decrypt(routingKey))
> +                return null;
> +
> +            StorableBlock block = callback.construct(data, header, routingKey,

fullKey);
> +            byte[] blockRoutingKey = block.getRoutingKey();
> +
> +            if (!Arrays.equals(blockRoutingKey, routingKey)) {
> +                // either the data is corrupted or we have found a SHA-1 collision
> +                // can't recover, as decrypt() depends on a correct route key
> +                return null;
> +            }
> +
> +            return block;
> +        }


If we can't be sure that the Entry isn't re-encrypted, we should copy the
data/headers here. If we can, we should document it.
> +
> +    /**
> +     * Check if a block is free
> +     *
> +     * @param offset
> +     * @throws IOException
> +     */
> +    private boolean isFree(long offset) throws IOException {
> +        int split = (int) (offset % FILE_SPLIT);
> +        long rawOffset = (offset / FILE_SPLIT) * entryTotalLength;
> +
> +        ByteBuffer bf = ByteBuffer.allocate((int) ENTRY_HEADER_LENGTH);
> +
> +        do {
> +            int status = storeFC[split].write(bf, rawOffset + bf.position());
> +            if (status == -1)
> +                throw new EOFException();
> +        } while (bf.hasRemaining());
> +
> +        return (bf.getLong(0x30) & ENTRY_FLAG_OCCUPIED) == 0;
> +    }


Why read the whole entry just to check one byte (or one long)?