Skip to content

Commit

Permalink
correctly handle max block size in api
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Feb 26, 2024
1 parent dff5c21 commit 392d590
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/org/peergos/EmbeddedIpfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public EmbeddedIpfs(Host node,
() -> blockstore.refs(false).join().stream(), node, dht, q));
}

public int maxBlockSize() {
return bitswap.maxBlockSize();
}

public List<HashedBlock> getBlocks(List<Want> wants, Set<PeerId> peers, boolean addToLocal) {
List<HashedBlock> blocksFound = new ArrayList<>();

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/peergos/net/APIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public class APIHandler extends Handler {
public static final String FIND_PROVS = "dht/findprovs";

private final EmbeddedIpfs ipfs;
private final int maxBlockSize;

public APIHandler(EmbeddedIpfs ipfs) {
this.ipfs = ipfs;
this.maxBlockSize = ipfs.maxBlockSize();
}

public void handleCallToAPI(HttpExchange httpExchange) {
Expand Down Expand Up @@ -109,7 +111,7 @@ public void handleCallToAPI(HttpExchange httpExchange) {
throw new APIException("Multiple input not supported");
}
byte[] block = data.get(0);
if (block.length > 1024 * 1024 * 2) { //todo what should the limit be?
if (block.length > maxBlockSize) {
throw new APIException("Block too large");
}
Cid cid = ipfs.blockstore.put(block, Cid.Codec.lookupIPLDName(reqFormat)).join();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/peergos/protocol/bitswap/Bitswap.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public void setAddressBook(AddressBook addrs) {
this.addrs = addrs;
}

public int maxBlockSize() {
return engine.maxMessageSize();
}

@Override
public void handleConnection(@NotNull Connection connection) {
// add all outgoing connections to an LRU of candidates
Expand Down

0 comments on commit 392d590

Please sign in to comment.