Skip to content

Commit

Permalink
feat(core): Introduce BlobStore & IdStore APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Feb 28, 2025
1 parent 95c66e3 commit 13e6772
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
1 change: 1 addition & 0 deletions java/dev/enola/cas/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ java_binary(
),
visibility = ["//:__subpackages__"],
deps = [
"//java/dev/enola/common",
"//java/dev/enola/common/context",
"//java/dev/enola/common/io",
"@enola_maven//:com_github_ipld_java_cid",
Expand Down
45 changes: 45 additions & 0 deletions java/dev/enola/cas/BlobStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2025 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.cas;

import com.google.common.io.ByteSource;

import io.ipfs.cid.Cid;

/**
* BlobStore stores bytes, which can then be loaded given their CID.
*
* <p>Note that this interface per-se does not specify anything about how this may be implemented...
* just with simple non-distributed local files. Or into a Key Value Store. Or e.g. with <a
* href="https://github.com/systemd/casync/">systemd casync</a>. Or may be on <a
* href="https://ipfs.tech/>IPFS</a>, either in <a href="https://ipld.io/specs/transport/car/">CAR
* files</a>, or it may be distributed (with <a
* href="https://docs.ipfs.tech/install/command-line/">IPFS Bitswap with Kubo</a>, or <a
* href="https://github.com/Peergos/nabu">Nabu</a>; or perhaps on the <a
* href="https://iroh.network/">Iroh Network</a> based on <a
* href="https://www.iroh.computer/">Iroh</a> by <a href="https://n0.computer/">number0</a>. Or
* something else, maybe based on Consensus with Raft or Paxos.
*/
public interface BlobStore {

Cid store(ByteSource source);

ByteSource load(Cid cid);

// TODO void delete(Cid cid)
}
43 changes: 43 additions & 0 deletions java/dev/enola/cas/IPFS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2025 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.cas;

import static java.util.Objects.requireNonNull;

import com.google.common.io.ByteSource;

import io.ipfs.cid.Cid;

public class IPFS implements BlobStore { // TODO , IdStore

private final IPFSResource.Provider ipfsResourceProvider;

public IPFS(IPFSResource.Provider ipfsResourceProvider) {
this.ipfsResourceProvider = ipfsResourceProvider;
}

@Override
public Cid store(ByteSource source) {
throw new UnsupportedOperationException();
}

@Override
public ByteSource load(Cid cid) {
return requireNonNull(ipfsResourceProvider.get("ipfs:" + cid)).byteSource();
}
}
32 changes: 32 additions & 0 deletions java/dev/enola/cas/IdStore.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2025 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.cas;

import com.google.common.primitives.Bytes;

import dev.enola.common.ByteSeq;

import io.ipfs.cid.Cid;

/** IdStore stores links of IDs of bytes to CIDs. */
public interface IdStore {

void link(ByteSeq bytes, Cid cid);

Cid get(Bytes link);
}
4 changes: 2 additions & 2 deletions java/dev/enola/common/io/resource/ResourceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public interface ResourceProvider extends ProviderFromIRI<Resource> {

// TODO Rename all parameters from iri or uri to url - because that's what these are!

// TODO Change all @Nullable Resource to Optional<Resource>... or, better, throw exception for
// unknown schema
// TODO Separate @NonNull SPI provider, instead of changing all @Nullable Resource to
// Optional<Resource>... or, better, throw exception for unknown schema

// TODO Should this have a Resource getResource(URI uri, MediaType mediaType) ?

Expand Down

0 comments on commit 13e6772

Please sign in to comment.