mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Add BlockSink interface, using temporary message ID.
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
package org.briarproject.bramble.api.io;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
import org.briarproject.bramble.api.sync.tree.TreeHash;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface BlockSink {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a block of the message with the given temporary ID.
|
||||||
|
*/
|
||||||
|
void putBlock(HashingId h, int blockNumber, byte[] data) throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the hash tree path of a previously stored block.
|
||||||
|
*/
|
||||||
|
void setPath(HashingId h, int blockNumber, List<TreeHash> path)
|
||||||
|
throws DbException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the permanent ID of the message with the given temporary ID. The
|
||||||
|
* temporary ID is no longer valid once this method has been called.
|
||||||
|
*/
|
||||||
|
void setMessageId(HashingId h, MessageId m) throws DbException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.briarproject.bramble.api.io;
|
||||||
|
|
||||||
|
import org.briarproject.bramble.api.UniqueId;
|
||||||
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
import org.briarproject.bramble.api.sync.Message;
|
||||||
|
import org.briarproject.bramble.api.sync.MessageId;
|
||||||
|
|
||||||
|
import javax.annotation.concurrent.ThreadSafe;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type-safe wrapper for a byte array that uniquely identifies a
|
||||||
|
* {@link Message} while it's being hashed and the {@link MessageId} is not
|
||||||
|
* yet known.
|
||||||
|
*/
|
||||||
|
@ThreadSafe
|
||||||
|
@NotNullByDefault
|
||||||
|
public class HashingId extends UniqueId {
|
||||||
|
|
||||||
|
public HashingId(byte[] id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
return o instanceof HashingId && super.equals(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,4 +35,9 @@ public interface SyncConstants {
|
|||||||
* The maximum number of message IDs in an ack, offer or request record.
|
* The maximum number of message IDs in an ack, offer or request record.
|
||||||
*/
|
*/
|
||||||
int MAX_MESSAGE_IDS = MAX_RECORD_PAYLOAD_BYTES / UniqueId.LENGTH;
|
int MAX_MESSAGE_IDS = MAX_RECORD_PAYLOAD_BYTES / UniqueId.LENGTH;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum length of a message block in bytes.
|
||||||
|
*/
|
||||||
|
int MAX_BLOCK_LENGTH = 32 * 2014; // 32 KiB
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user