-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Introduce BlobStore & IdStore APIs
- Loading branch information
Showing
5 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters