Skip to content

Commit

Permalink
Merge upstream (#19)
Browse files Browse the repository at this point in the history
- Merge updates from the upstream;

- Remove jar minimisation so that we can rely on some necessary dependencies from the public interface for our use case.
  • Loading branch information
David-Petrov authored Apr 29, 2024
1 parent 26c966a commit 16c6586
Show file tree
Hide file tree
Showing 93 changed files with 3,589 additions and 440 deletions.
16 changes: 8 additions & 8 deletions .github/actions/local-s3/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ runs:
echo 'MINIO_ROOT_USER=test' >> $GITHUB_ENV
echo 'MINIO_ROOT_PASSWORD=testdslocal' >> $GITHUB_ENV
if [[ '${{ runner.os }}' == 'Linux' ]]; then
echo '::set-output name=release::linux-amd64'
echo '::set-output name=home::/usr/local/bin'
echo 'release=linux-amd64' >> $GITHUB_OUTPUT
echo 'home=/usr/local/bin' >> $GITHUB_OUTPUT
elif [[ '${{ runner.os }}' == 'Windows' ]]; then
echo '::set-output name=release::windows-amd64'
echo "::set-output name=home::/usr/bin"
echo 'release=windows-amd64' >> $GITHUB_OUTPUT
echo "home=/usr/bin" >> $GITHUB_OUTPUT
elif [[ '${{ runner.os }}' == 'macOS' ]]; then
echo '::set-output name=release::darwin-amd64'
echo '::set-output name=home::/usr/local/bin'
echo 'release=darwin-amd64' >> $GITHUB_OUTPUT
echo 'home=/usr/local/bin' >> $GITHUB_OUTPUT
fi
- name: Download minio
shell: bash
run: |
curl --retry 5 --no-progress-meter --output '${{ steps.minio.outputs.home }}/minio' 'https://dl.min.io/server/minio/release/${{ steps.minio.outputs.release }}/archive/minio.RELEASE.2021-07-15T22-27-34Z'
curl --retry 5 --no-progress-meter --output '${{ steps.minio.outputs.home }}/mc' 'https://dl.min.io/client/mc/release/${{ steps.minio.outputs.release }}/archive/mc.RELEASE.2021-07-27T06-46-19Z'
curl --retry 5 --no-progress-meter --output '${{ steps.minio.outputs.home }}/minio' 'https://dl.min.io/server/minio/release/${{ steps.minio.outputs.release }}/archive/minio.RELEASE.2023-10-07T15-07-38Z'
curl --retry 5 --no-progress-meter --output '${{ steps.minio.outputs.home }}/mc' 'https://dl.min.io/client/mc/release/${{ steps.minio.outputs.release }}/archive/mc.RELEASE.2023-10-04T06-52-56Z'
chmod +x '${{ steps.minio.outputs.home }}/minio'
chmod +x '${{ steps.minio.outputs.home }}/mc'
- name: Start minio
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ target/*
*.hprof
*hs_err_pid*
*~
**/dependency-reduced-pom.xml
8 changes: 3 additions & 5 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ LABEL org.opencontainers.image.description="Nabu is a minimal Java implementatio
LABEL org.opencontainers.image.source="https://github.com/Peergos/nabu"
LABEL org.opencontainers.image.licenses="MIT license"

ENV IPFS_PATH=/opt/nabu/.ipfs

WORKDIR /opt/nabu
RUN mkdir -p /opt/nabu/.ipfs

COPY --from=build /opt/nabu/target /opt/nabu

ENTRYPOINT ["java", "-cp", "/opt/nabu/nabu-v0.0.1-SNAPSHOT-jar-with-dependencies.jar", "org.peergos.Nabu", "Addresses.API", "/ip4/0.0.0.0/tcp/5001"]
ENTRYPOINT ["java", "-cp", "/opt/nabu/nabu-v0.7.4-jar-with-dependencies.jar", "org.peergos.client.InteropTestClient"]

EXPOSE 4001 5001 8080 8000
EXPOSE 4001
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![logo](assets/nabu-logo.png)

# Nabu

A minimal Java implementation of [IPFS](https://ipfs.io)
Expand Down Expand Up @@ -27,14 +29,16 @@ Currently implemented properties:
* bloom/[infini filtered](https://www.rasmuspagh.net/papers/infinifilter.pdf) blockstore
* connect bitswap to kademlia for discovery, with a faster version with supplied peerids
* configurable cid publishing function
* Android compatibility
* example serverless chat app using p2p http proxy for Android
* interop tests with other implementations - https://github.com/libp2p/test-plans/

In the future we will add:
* circuit-relay
* dcutr (direct connection upgrade through relay)
* AutoRelay
* mDNS peer discovery
* Android compatibility
* example serverless chat app using p2p http proxy for Android and iOS
* example iOS chat app
* QUIC transport (and encryption and multiplexing)

## Usage
Expand Down Expand Up @@ -63,6 +67,48 @@ for Maven, add the following sections to your pom.xml (replacing $LATEST_VERSION
```


Build using Maven

```
mvn package -Dmaven.test.skip=true
```


### Embedded usage
```java
List<MultiAddress> swarmAddresses = List.of(new MultiAddress("/ip6/::/tcp/4001"));
List<MultiAddress> bootstrapAddresses = List.of(new MultiAddress("/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa"));
BlockRequestAuthoriser authoriser = (cid, peerid, auth) -> CompletableFuture.completedFuture(true);
HostBuilder builder = new HostBuilder().generateIdentity();
PrivKey privKey = builder.getPrivateKey();
PeerId peerId = builder.getPeerId();
IdentitySection identity = new IdentitySection(privKey.bytes(), peerId);
boolean provideBlocks = true;

SocketAddress httpTarget = new InetSocketAddress("localhost", 10000);
Optional<HttpProtocol.HttpRequestProcessor> httpProxyTarget =
Optional.of((s, req, h) -> HttpProtocol.proxyRequest(req, httpTarget, h));

EmbeddedIpfs ipfs = EmbeddedIpfs.build(new RamRecordStore(),
new FileBlockstore(Path.of("/home/alice/ipfs")),
provideBlocks,
swarmAddresses,
bootstrapAddresses,
identity,
authoriser,
httpProxyTarget
);
ipfs.start();

List<Want> wants = List.of(new Want(Cid.decode("zdpuAwfJrGYtiGFDcSV3rDpaUrqCtQZRxMjdC6Eq9PNqLqTGg")));
Set<PeerId> retrieveFrom = Set.of(PeerId.fromBase58("QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF"));
boolean addToLocal = true;
List<HashedBlock> blocks = ipfs.getBlocks(wants, retrieveFrom, addToLocal);
byte[] data = blocks.get(0).block;
```
### Demo app
If you want a working example app you can fork, have a look at our [chat example](https://github.com/Peergos/nabu-chat). This is a simple CLI app where two users exchange peerid (out of band) and then connect and send messages via p2p http requests, which are printed to the console.

### S3 Blockstore

By default, Nabu will construct a File based blockstore
Expand Down
98 changes: 98 additions & 0 deletions assets/nabu-logo.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<mxfile host="app.diagrams.net" modified="2023-11-05T18:56:13.253Z" agent="Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0" etag="7Pc30QILimTA8fWvTUge" version="22.0.8" type="device">
<diagram name="Page-1" id="tmMb_pmpO9FEe4IHUe_x">
<mxGraphModel dx="1698" dy="1060" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="ebzSuSit2eP1TeJUkmYe-18" value="" style="whiteSpace=wrap;html=1;aspect=fixed;strokeWidth=16;rounded=1;strokeColor=#3c5980;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="640" y="570" width="400" height="400" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-14" value="" style="whiteSpace=wrap;html=1;aspect=fixed;strokeWidth=16;rounded=1;strokeColor=#3c5980;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="160" y="120" width="400" height="400" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-6" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="260" y="230" as="sourcePoint" />
<mxPoint x="480" y="480" as="targetPoint" />
<Array as="points">
<mxPoint x="360" y="150" />
<mxPoint x="490" y="250" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-10" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#3c5980;strokeColor=#3c5980;" vertex="1" parent="1">
<mxGeometry x="240" y="160" width="40" height="320" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-11" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="730" y="610" as="sourcePoint" />
<mxPoint x="930" y="860" as="targetPoint" />
<Array as="points">
<mxPoint x="720" y="870" />
<mxPoint x="890" y="940" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-12" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#3c5980;strokeColor=#3c5980;" vertex="1" parent="1">
<mxGeometry x="910" y="610" width="40" height="320" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-19" value="" style="whiteSpace=wrap;html=1;aspect=fixed;strokeWidth=16;rounded=1;strokeColor=#3c5980;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="640" y="120" width="400" height="400" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-20" value="" style="whiteSpace=wrap;html=1;aspect=fixed;strokeWidth=16;rounded=1;strokeColor=#3c5980;fillColor=none;" vertex="1" parent="1">
<mxGeometry x="160" y="570" width="400" height="400" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-21" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#3c5980;strokeColor=#3c5980;" vertex="1" parent="1">
<mxGeometry x="290" y="610" width="40" height="320" as="geometry" />
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-22" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="300" y="630" as="sourcePoint" />
<mxPoint x="300" y="760" as="targetPoint" />
<Array as="points">
<mxPoint x="440" y="610" />
<mxPoint x="460" y="740" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-24" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="300" y="780" as="sourcePoint" />
<mxPoint x="320" y="910" as="targetPoint" />
<Array as="points">
<mxPoint x="440" y="760" />
<mxPoint x="460" y="890" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-28" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="850" y="190" as="sourcePoint" />
<mxPoint x="730" y="480" as="targetPoint" />
<Array as="points">
<mxPoint x="760" y="320" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-29" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="840" y="200" as="sourcePoint" />
<mxPoint x="970" y="480" as="targetPoint" />
<Array as="points">
<mxPoint x="850" y="360" />
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ebzSuSit2eP1TeJUkmYe-30" value="" style="curved=1;endArrow=none;html=1;rounded=0;endFill=0;fillColor=#3C5980;strokeColor=#3C5980;strokeWidth=37;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="900" y="360" as="sourcePoint" />
<mxPoint x="720" y="380" as="targetPoint" />
<Array as="points">
<mxPoint x="750" y="320" />
</Array>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Binary file added assets/nabu-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/nabu-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added blocks.bin
Binary file not shown.
1 change: 0 additions & 1 deletion install-run-ipfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ export PATH=$PATH:$PWD/kubo/
ipfs init
ipfs daemon --routing=dhtserver &
sleep 10s
time ipfs pin add zdpuAwfJrGYtiGFDcSV3rDpaUrqCtQZRxMjdC6Eq9PNqLqTGg
Loading

0 comments on commit 16c6586

Please sign in to comment.