mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Set paths on blocks after hashing.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
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;
|
||||
@@ -18,10 +17,4 @@ public interface BlockSink {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,21 @@
|
||||
package org.briarproject.bramble.api.sync.tree;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public class LeafNode extends TreeNode {
|
||||
|
||||
public LeafNode(TreeHash hash, int blockNumber) {
|
||||
super(hash, 0, blockNumber, blockNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getLeftChild() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getRightChild() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,26 @@
|
||||
package org.briarproject.bramble.api.sync.tree;
|
||||
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public class ParentNode extends TreeNode {
|
||||
|
||||
private final TreeNode left, right;
|
||||
|
||||
public ParentNode(TreeHash hash, TreeNode left, TreeNode right) {
|
||||
super(hash, Math.max(left.getHeight(), right.getHeight()) + 1,
|
||||
left.getFirstBlockNumber(), right.getLastBlockNumber());
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getLeftChild() {
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreeNode getRightChild() {
|
||||
return right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.io.BlockSink;
|
||||
import org.briarproject.bramble.api.io.HashingId;
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.MessageId;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -16,8 +14,8 @@ public interface StreamHasher {
|
||||
/**
|
||||
* Reads the given input stream, divides the data into blocks, stores
|
||||
* the blocks and the resulting hash tree using the given block sink and
|
||||
* temporary ID, and returns the message ID.
|
||||
* temporary ID, and returns the hash tree.
|
||||
*/
|
||||
MessageId hash(InputStream in, BlockSink sink, HashingId h, GroupId g,
|
||||
long timestamp) throws IOException, DbException;
|
||||
TreeNode hash(InputStream in, BlockSink sink, HashingId h)
|
||||
throws IOException, DbException;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package org.briarproject.bramble.api.sync.tree;
|
||||
|
||||
public class TreeNode {
|
||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||
|
||||
@NotNullByDefault
|
||||
public abstract class TreeNode {
|
||||
|
||||
private final TreeHash hash;
|
||||
private final int height, firstBlockNumber, lastBlockNumber;
|
||||
@@ -28,4 +31,8 @@ public class TreeNode {
|
||||
public int getLastBlockNumber() {
|
||||
return lastBlockNumber;
|
||||
}
|
||||
|
||||
public abstract TreeNode getLeftChild();
|
||||
|
||||
public abstract TreeNode getRightChild();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user