/
Blockstore.java
40 lines (27 loc) · 1.11 KB
/
Blockstore.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.peergos.blockstore;
import io.ipfs.cid.*;
import io.ipfs.multibase.binary.Base32;
import io.ipfs.multihash.Multihash;
import org.peergos.blockstore.metadatadb.BlockMetadata;
import org.peergos.blockstore.metadatadb.BlockMetadataStore;
import java.util.*;
import java.util.concurrent.*;
public interface Blockstore {
default String hashToKey(Multihash hash) {
String padded = new Base32().encodeAsString(hash.toBytes());
int padStart = padded.indexOf("=");
return padStart > 0 ? padded.substring(0, padStart) : padded;
}
default Cid keyToHash(String key) {
byte[] decoded = new Base32().decode(key);
return Cid.cast(decoded);
}
CompletableFuture<Boolean> has(Cid c);
CompletableFuture<Boolean> hasAny(Multihash h);
CompletableFuture<Optional<byte[]>> get(Cid c);
CompletableFuture<Cid> put(byte[] block, Cid.Codec codec);
CompletableFuture<Boolean> rm(Cid c);
CompletableFuture<List<Cid>> refs(boolean useBlockstore);
CompletableFuture<Boolean> bloomAdd(Cid cid);
CompletableFuture<BlockMetadata> getBlockMetadata(Cid h);
}