### S3 Blockstore Configuration Source: https://context7.com/peergos/nabu/llms.txt Configuration guide for using S3-compatible storage as a blockstore backend. ```APIDOC ### S3 Blockstore Configuration Configure Nabu to use S3-compatible storage backends for scalable cloud deployments. ```java import org.peergos.blockstore.s3.S3Blockstore; import org.peergos.blockstore.metadatadb.*; import org.peergos.config.*; import java.util.*; // Create S3 configuration parameters Map s3Params = new HashMap<>(); s3Params.put("region", "us-east-1"); s3Params.put("bucket", "my-ipfs-blocks"); s3Params.put("rootDirectory", "nabu/blocks"); s3Params.put("regionEndpoint", "s3.amazonaws.com"); // Optional: set credentials (can also use env vars or ~/.aws/credentials) s3Params.put("accessKey", System.getenv("AWS_ACCESS_KEY_ID")); s3Params.put("secretKey", System.getenv("AWS_SECRET_ACCESS_KEY")); // Create block metadata store for tracking BlockMetadataStore metadataStore = EmbeddedIpfs.buildBlockMetadata(args); // Create S3 blockstore S3Blockstore s3Blockstore = new S3Blockstore(s3Params, metadataStore); // Update metadata store from existing S3 data (run once on initialization) boolean updateMetadata = true; if (updateMetadata) { s3Blockstore.updateMetadataStoreIfEmpty(); } // Use in EmbeddedIpfs.build() instead of FileBlockstore EmbeddedIpfs ipfs = EmbeddedIpfs.build( new RamRecordStore(), s3Blockstore, provideBlocks, swarmAddresses, bootstrapAddresses, identity, authoriser, Optional.empty() ); // All blockstore operations now use S3 Cid cid = s3Blockstore.put("data".getBytes(), Cid.Codec.Raw).join(); Optional data = s3Blockstore.get(cid).join(); ``` ``` -------------------------------- ### Embed Nabu IPFS in a Java Application Source: https://github.com/peergos/nabu/blob/master/README.md Example of embedding Nabu IPFS into a Java application. It demonstrates building an 'EmbeddedIpfs' instance with various configurations like swarm addresses, bootstrap nodes, identity, authorizer, and an optional HTTP proxy. It also shows how to start the IPFS instance and retrieve blocks. ```java List swarmAddresses = List.of(new MultiAddress("/ip6/::/tcp/4001")); List 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 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 wants = List.of(new Want(Cid.decode("zdpuAwfJrGYtiGFDcSV3rDpaUrqCtQZRxMjdC6Eq9PNqLqTGg"))); Set retrieveFrom = Set.of(PeerId.fromBase58("QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF")); boolean addToLocal = true; List blocks = ipfs.getBlocks(wants, retrieveFrom, addToLocal); byte[] data = blocks.get(0).block; ``` -------------------------------- ### Peergos Nabu Block Management API (cURL) Source: https://context7.com/peergos/nabu/llms.txt Examples demonstrating how to manage blocks in Peergos Nabu using cURL commands. This includes getting block statistics, removing blocks, listing local blocks, and finding providers for a content identifier (CID). ```bash # Get block statistics curl "http://localhost:5001/api/v0/block/stat?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" # Response: {"Size":1024} # Remove a block curl "http://localhost:5001/api/v0/block/rm?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" # Response: {"Error":"","Hash":"QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"} # List all local blocks curl "http://localhost:5001/api/v0/refs/local" # Response: {"Ref":"QmY...","Err":""}{"Ref":"Qmb...","Err":""}... # Find providers for a CID curl "http://localhost:5001/api/v0/dht/findprovs?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG&num-providers=5" # Resolve IPNS name curl "http://localhost:5001/api/v0/ipns/get?arg=QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF" # Response: {"sig":"a1b2c3...","data":"d4e5f6..."} ``` -------------------------------- ### Kademlia DHT Operations Source: https://context7.com/peergos/nabu/llms.txt Code examples for interacting with the Kademlia DHT for peer routing and content discovery. ```APIDOC ```java import org.peergos.protocol.dht.*; import io.ipfs.multihash.Multihash; import io.ipfs.cid.Cid; import java.util.List; Kademlia dht = ipfs.dht; Host node = ipfs.node; // Find closest peers to a given peer ID byte[] targetPeerId = Multihash.fromBase58("QmTargetPeer123...").toBytes(); int maxPeers = 20; List closestPeers = dht.findClosestPeers(targetPeerId, maxPeers, node); System.out.println("Found " + closestPeers.size() + " peers:"); for (PeerAddresses peer : closestPeers) { System.out.println(" Peer: " + peer.peerId.toBase58()); System.out.println(" Addresses: " + peer.addresses); } // Find providers for a specific CID Cid contentCid = Cid.decode("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"); int numProviders = 10; CompletableFuture> providersFuture = dht.findProviders(contentCid, node, numProviders); List providers = providersFuture.join(); System.out.println("Found " + providers.size() + " providers for " + contentCid); // Bootstrap the routing table with seed nodes List bootstrapNodes = List.of( new MultiAddress("/ip4/147.75.83.83/tcp/4001/p2p/QmW9m57aiBDHAkKj9nmFSEn7ZqrcF1fZS4bipsTCHburei") ); int connected = dht.bootstrapRoutingTable(node, bootstrapNodes, addr -> true); System.out.println("Connected to " + connected + " bootstrap nodes"); // Perform periodic bootstrap to refresh routing table dht.bootstrap(node); ``` ``` -------------------------------- ### Create and Configure Embedded IPFS Node in Java Source: https://context7.com/peergos/nabu/llms.txt This code snippet demonstrates how to create and configure an embedded IPFS node using the Nabu library. It covers setting up swarm and bootstrap addresses, generating node identity, authorizing block requests, and initializing the IPFS node with a file-based blockstore. The node can then be started to bootstrap to the IPFS network. ```java import org.peergos.*; import org.peergos.blockstore.*; import org.peergos.config.*; import io.ipfs.multiaddr.MultiAddress; import io.libp2p.core.crypto.PrivKey; import io.libp2p.core.PeerId; import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; import java.net.*; // Configure swarm and bootstrap addresses List swarmAddresses = List.of( new MultiAddress("/ip6/::/tcp/4001"), new MultiAddress("/ip4/0.0.0.0/tcp/4001") ); List bootstrapAddresses = List.of( new MultiAddress("/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa"), new MultiAddress("/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN") ); // Generate node identity HostBuilder builder = new HostBuilder().generateIdentity(); PrivKey privKey = builder.getPrivateKey(); PeerId peerId = builder.getPeerId(); IdentitySection identity = new IdentitySection(privKey.bytes(), peerId); // Configure block request authorization (allow all in this example) BlockRequestAuthoriser authoriser = (cid, peerid, auth) -> CompletableFuture.completedFuture(true); // Build the IPFS node with file-based blockstore boolean provideBlocks = true; EmbeddedIpfs ipfs = EmbeddedIpfs.build( new RamRecordStore(), new FileBlockstore(Path.of("/home/user/.ipfs/blocks")), provideBlocks, swarmAddresses, bootstrapAddresses, identity, authoriser, Optional.empty() ); // Start the node and bootstrap to the network ipfs.start(false); // false = synchronous bootstrap System.out.println("IPFS node started with peer ID: " + peerId.toBase58()); ``` -------------------------------- ### Block Storage Operations in Java Source: https://context7.com/peergos/nabu/llms.txt Demonstrates how to store, retrieve, check existence, and remove blocks in the local blockstore using different codec formats like Raw and DagCbor. It also shows how to list all blocks and get the total block count. This functionality is crucial for managing data persistence within the IPFS network. ```java import io.ipfs.cid.*; import org.peergos.blockstore.*; import java.util.Optional; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; // Assuming 'ipfs' is an initialized instance of your IPFS client Blockstore blockstore = ipfs.blockstore; // Store raw binary data byte[] rawData = "Hello, IPFS!".getBytes(); CompletableFuture cidFuture = blockstore.put(rawData, Cid.Codec.Raw); Cid rawCid = cidFuture.join(); System.out.println("Stored raw block: " + rawCid); // Store CBOR data (common for IPLD structures) // Placeholder for actual CBOR encoding function // byte[] cborData = encodeToCbor(Map.of("name", "Alice", "age", 30)); // Cid cborCid = blockstore.put(cborData, Cid.Codec.DagCbor).join(); // Check if block exists boolean exists = blockstore.has(rawCid).join(); System.out.println("Block exists: " + exists); // Retrieve block CompletableFuture> dataFuture = blockstore.get(rawCid); Optional data = dataFuture.join(); data.ifPresent(bytes -> System.out.println("Retrieved: " + new String(bytes))); // Remove block boolean removed = blockstore.rm(rawCid).join(); System.out.println("Block removed: " + removed); // List all local blocks List allBlocks = blockstore.refs(false).join(); System.out.println("Total blocks in store: " + allBlocks.size()); // Get block count long count = blockstore.count(false).join(); System.out.println("Block count: " + count); ``` -------------------------------- ### Block Operations Source: https://context7.com/peergos/nabu/llms.txt APIs for managing blocks, including getting statistics, removing blocks, and listing local blocks. ```APIDOC ## GET /api/v0/block/stat ### Description Retrieves statistics for a given block identified by its CID. ### Method GET ### Endpoint /api/v0/block/stat ### Parameters #### Query Parameters - **arg** (string) - Required - The Content Identifier (CID) of the block. ### Response #### Success Response (200) - **Size** (integer) - The size of the block in bytes. #### Response Example ```json { "Size": 1024 } ``` ## DELETE /api/v0/block/rm ### Description Removes a block from the local blockstore. ### Method DELETE ### Endpoint /api/v0/block/rm ### Parameters #### Query Parameters - **arg** (string) - Required - The Content Identifier (CID) of the block to remove. ### Response #### Success Response (200) - **Error** (string) - An error message if the removal failed, otherwise empty. - **Hash** (string) - The CID of the removed block. #### Response Example ```json { "Error": "", "Hash": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" } ``` ## GET /api/v0/refs/local ### Description Lists all blocks that are locally available in the blockstore. ### Method GET ### Endpoint /api/v0/refs/local ### Response #### Success Response (200) - **Ref** (string) - The CID of a local block. - **Err** (string) - An error message, if any. #### Response Example ```json { "Ref": "QmY...", "Err": "" } { "Ref": "Qmb...", "Err": "" } ``` ``` -------------------------------- ### HTTP API Server Usage (Bash) Source: https://context7.com/peergos/nabu/llms.txt Illustrates how to interact with an embedded IPFS node's HTTP API using `curl` commands. This covers essential operations like getting the node's identity, storing a block using `block/put`, retrieving a block with `block/get`, and checking block existence with `block/has`. The API is compatible with Kubo and typically runs on `http://localhost:5001`. ```bash # Start an IPFS node with HTTP API enabled (in Java code, configure APIHandler) # The API runs on http://localhost:5001 by default # Get node identity curl "http://localhost:5001/api/v0/id" # Response: {"ID":"QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF"} # Store a block echo "Hello IPFS" | curl -X POST -F file=@- \ "http://localhost:5001/api/v0/block/put?format=raw" # Response: {"Hash":"bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e"} # Retrieve a block curl "http://localhost:5001/api/v0/block/get?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" # Response: (raw block bytes) # Check if block exists curl "http://localhost:5001/api/v0/block/has?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" # Response: true ``` -------------------------------- ### Peergos Nabu S3 Blockstore Configuration (Java) Source: https://context7.com/peergos/nabu/llms.txt Java code for configuring Nabu to use S3-compatible storage. This includes setting up S3 parameters like region, bucket, and root directory, creating a metadata store, initializing the S3 blockstore, and updating the metadata store. Finally, it shows how to use the S3 blockstore with `EmbeddedIpfs.build()` and perform basic operations like putting and getting data. ```java import org.peergos.blockstore.s3.S3Blockstore; import org.peergos.blockstore.metadatadb.*; import org.peergos.config.*; import java.util.*; // Create S3 configuration parameters Map s3Params = new HashMap<>(); s3Params.put("region", "us-east-1"); s3Params.put("bucket", "my-ipfs-blocks"); s3Params.put("rootDirectory", "nabu/blocks"); s3Params.put("regionEndpoint", "s3.amazonaws.com"); // Optional: set credentials (can also use env vars or ~/.aws/credentials) s3Params.put("accessKey", System.getenv("AWS_ACCESS_KEY_ID")); s3Params.put("secretKey", System.getenv("AWS_SECRET_ACCESS_KEY")); // Create block metadata store for tracking BlockMetadataStore metadataStore = EmbeddedIpfs.buildBlockMetadata(args); // Create S3 blockstore S3Blockstore s3Blockstore = new S3Blockstore(s3Params, metadataStore); // Update metadata store from existing S3 data (run once on initialization) boolean updateMetadata = true; if (updateMetadata) { s3Blockstore.updateMetadataStoreIfEmpty(); } // Use in EmbeddedIpfs.build() instead of FileBlockstore EmbeddedIpfs ipfs = EmbeddedIpfs.build( new RamRecordStore(), s3Blockstore, provideBlocks, swarmAddresses, bootstrapAddresses, identity, authoriser, Optional.empty() ); // All blockstore operations now use S3 Cid cid = s3Blockstore.put("data".getBytes(), Cid.Codec.Raw).join(); Optional data = s3Blockstore.get(cid).join(); ``` -------------------------------- ### IPNS Record Resolution in Java Source: https://context7.com/peergos/nabu/llms.txt Details the process of resolving IPNS names to their current values by querying the Distributed Hash Table (DHT). It requires the publisher's public key and a minimum number of DHT responses. The example shows how to retrieve the resolved value, handle potential errors, and optionally retrieve all record versions. ```java import io.libp2p.core.PeerId; import io.libp2p.core.crypto.PubKey; import io.ipfs.cid.Cid; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; // Assuming 'ipfs' is an initialized instance of your IPFS client // Public key of the publisher (can be extracted from peer ID) // PeerId publisherId = PeerId.fromBase58("QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF"); // PubKey pubKey = publisherId.getPubKey(); // Placeholder for PubKey retrieval // PubKey pubKey = ...; // Minimum number of DHT responses required for resolution int minResults = 1; // Resolve the IPNS name // CompletableFuture resolveFuture = ipfs.resolveValue(pubKey, minResults); // Placeholder for actual resolve call CompletableFuture resolveFuture = CompletableFuture.completedFuture("/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG".getBytes()); try { byte[] resolvedValue = resolveFuture.join(); String path = new String(resolvedValue); System.out.println("IPNS resolved to: " + path); // If it's a CID path, you can now retrieve the content if (path.startsWith("/ipfs/")) { String cidStr = path.substring(6); // Assuming Cid class is available and can decode // Cid cid = Cid.decode(cidStr); // List content = ipfs.getBlocks( // List.of(new Want(cid)), // Collections.emptySet(), // true // ); } } catch (Exception e) { System.err.println("Failed to resolve IPNS name: " + e.getMessage()); } // For getting all record versions // Assuming Multihash and IpnsRecord classes are available // Multihash publisher = Multihash.fromBase58(publisherId.toBase58()); // List records = ipfs.resolveRecords(publisher, 3); // records.forEach(record -> // System.out.println("Sequence: " + record.sequence + ", Value: " + new String(record.value)) // ); ``` -------------------------------- ### Retrieve Blocks from IPFS Network in Java Source: https://context7.com/peergos/nabu/llms.txt This Java code snippet shows how to retrieve content-addressed blocks from the IPFS network using the Bitswap protocol. It allows specifying a list of CIDs to fetch, optionally targeting specific peers, and choosing whether to add retrieved blocks to the local blockstore. The example also includes a variation for retrieving blocks with authentication tokens. ```java import io.ipfs.cid.Cid; import org.peergos.*; import org.peergos.protocol.bitswap.Want; import io.libp2p.core.PeerId; import java.util.*; // Create a want list with the CIDs to retrieve List wants = Arrays.asList( new Want(Cid.decode("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG")), new Want(Cid.decode("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")) ); // Optionally specify peer IDs to retrieve from (empty set = query DHT for providers) Set retrieveFrom = Set.of( PeerId.fromBase58("QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF") ); // Retrieve blocks and add to local blockstore boolean addToLocal = true; try { List blocks = ipfs.getBlocks(wants, retrieveFrom, addToLocal); for (HashedBlock block : blocks) { System.out.println("Retrieved CID: " + block.hash); System.out.println("Block size: " + block.block.length + " bytes"); System.out.println("Data: " + new String(block.block)); } } catch (Exception e) { System.err.println("Failed to retrieve blocks: " + e.getMessage()); } // For single block retrieval with authentication Optional authToken = Optional.of("bat-token-here"); Want authenticatedWant = new Want( Cid.decode("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"), authToken ); List authBlocks = ipfs.getBlocks( List.of(authenticatedWant), Collections.emptySet(), true ); ``` -------------------------------- ### Build and Test Nabu from Source using Maven Source: https://context7.com/peergos/nabu/llms.txt Command-line instructions for building the Nabu project from source using Maven. This includes commands to package the application, skip tests during packaging, run tests separately, and create a JAR file with dependencies. These are essential for developers who need to build or test Nabu directly. ```bash # Build from source mvn package -Dmaven.test.skip=true # Run tests mvn test # Create JAR with dependencies mvn assembly:single ``` -------------------------------- ### Manage IPFS Node Configuration in Java Source: https://context7.com/peergos/nabu/llms.txt Demonstrates how to load, create, and manage IPFS node configurations with custom settings using the Nabu Java library. It covers accessing default configurations, customizing addresses, saving to a file, and loading from a file. This functionality is crucial for setting up and controlling an IPFS node within a Java application. ```java import org.peergos.config.*; import java.nio.file.*; import java.io.IOException; import java.util.List; import java.util.Optional; // Create default configuration Config config = new Config(); // Access configuration sections List swarmAddrs = config.addresses.getSwarmAddresses(); MultiAddress apiAddr = config.addresses.getApiAddress(); List bootstrapPeers = config.bootstrap.getBootstrapPeers(); PeerId nodeId = config.identity.peerId; // Customize configuration List customSwarm = List.of( new MultiAddress("/ip4/0.0.0.0/tcp/4001"), new MultiAddress("/ip6/::/tcp/4001"), new MultiAddress("/ip4/0.0.0.0/udp/4001/quic-v1") ); AddressesSection addresses = new AddressesSection( customSwarm, new MultiAddress("/ip4/127.0.0.1/tcp/5001"), new MultiAddress("/ip4/127.0.0.1/tcp/8080"), Optional.of(new MultiAddress("/ip4/127.0.0.1/tcp/8003")), Optional.of("http://localhost:8002") ); Config customConfig = new Config( addresses, config.bootstrap, config.datastore, config.identity, config.metrics ); // Save configuration to file String configJson = customConfig.toString(); Path configPath = Paths.get("/home/user/.ipfs/config"); try { Files.writeString(configPath, configJson); } catch (IOException e) { System.err.println("Failed to save config: " + e.getMessage()); } // Load configuration from file try { String contents = Files.readString(configPath); Config loadedConfig = Config.build(contents); System.out.println("Loaded config for peer: " + loadedConfig.identity.peerId.toBase58()); } catch (IOException e) { System.err.println("Failed to load config: " + e.getMessage()); } ``` -------------------------------- ### Embedded IPFS Instance Creation Source: https://context7.com/peergos/nabu/llms.txt This section demonstrates how to create and configure an embedded IPFS node using the Nabu library. It covers setting up network addresses, bootstrap peers, identity, and block request authorization. ```APIDOC ## Embedded IPFS Instance Creation ### Description Create and configure an embedded IPFS node with custom blockstore, network addresses, and bootstrap peers. ### Method Instantiation and Configuration ### Endpoint N/A (Embedded Instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```java import org.peergos.*; import org.peergos.blockstore.*; import org.peergos.config.*; import io.ipfs.multiaddr.MultiAddress; import io.libp2p.core.crypto.PrivKey; import io.libp2p.core.PeerId; import java.nio.file.Path; import java.util.*; import java.util.concurrent.CompletableFuture; import java.net.*; // Configure swarm and bootstrap addresses List swarmAddresses = List.of( new MultiAddress("/ip6/::/tcp/4001"), new MultiAddress("/ip4/0.0.0.0/tcp/4001") ); List bootstrapAddresses = List.of( new MultiAddress("/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa"), new MultiAddress("/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN") ); // Generate node identity HostBuilder builder = new HostBuilder().generateIdentity(); PrivKey privKey = builder.getPrivateKey(); PeerId peerId = builder.getPeerId(); IdentitySection identity = new IdentitySection(privKey.bytes(), peerId); // Configure block request authorization (allow all in this example) BlockRequestAuthoriser authoriser = (cid, peerid, auth) -> CompletableFuture.completedFuture(true); // Build the IPFS node with file-based blockstore boolean provideBlocks = true; EmbeddedIpfs ipfs = EmbeddedIpfs.build( new RamRecordStore(), new FileBlockstore(Path.of("/home/user/.ipfs/blocks")), provideBlocks, swarmAddresses, bootstrapAddresses, identity, authoriser, Optional.empty() ); // Start the node and bootstrap to the network ipfs.start(false); // false = synchronous bootstrap System.out.println("IPFS node started with peer ID: " + peerId.toBase58()); ``` ### Response #### Success Response (200) - **ipfs** (EmbeddedIpfs) - The initialized and started embedded IPFS node. #### Response Example ```json { "message": "IPFS node started with peer ID: " } ``` ``` -------------------------------- ### Build Nabu Project with Maven Source: https://github.com/peergos/nabu/blob/master/README.md Command to build the Nabu project using Maven. The '-Dmaven.test.skip=true' flag is used to skip running tests during the build process. ```bash mvn package -Dmaven.test.skip=true ``` -------------------------------- ### Configure S3 Blockstore for Nabu Source: https://github.com/peergos/nabu/blob/master/README.md Command-line argument to configure Nabu to use an S3-compatible object storage for its blockstore. The argument takes a JSON string specifying S3 connection details such as region, bucket, and optional credentials. ```bash -s3.datastore "{\"region\": \"us-east-1\", \"bucket\": \"$bucketname\", \"rootDirectory\": \"$bucketsubdirectory\", \"regionEndpoint\": \"us-east-1.linodeobjects.com\", \"accessKey\": \"1\", \"secretKey\": \"2\"}" ``` -------------------------------- ### Peergos Nabu Kademlia DHT Operations (Java) Source: https://context7.com/peergos/nabu/llms.txt Java code demonstrating Kademlia Distributed Hash Table (DHT) operations in Peergos. This includes finding closest peers to a target peer ID, finding providers for a given content CID, bootstrapping the routing table with seed nodes, and performing periodic bootstrapping. It assumes an initialized `ipfs` object with `dht` and `node` properties. ```java import org.peergos.protocol.dht.*; import io.ipfs.multihash.Multihash; import io.ipfs.cid.Cid; import java.util.List; Kademlia dht = ipfs.dht; Host node = ipfs.node; // Find closest peers to a given peer ID byte[] targetPeerId = Multihash.fromBase58("QmTargetPeer123...").toBytes(); int maxPeers = 20; List closestPeers = dht.findClosestPeers(targetPeerId, maxPeers, node); System.out.println("Found " + closestPeers.size() + " peers:"); for (PeerAddresses peer : closestPeers) { System.out.println(" Peer: " + peer.peerId.toBase58()); System.out.println(" Addresses: " + peer.addresses); } // Find providers for a specific CID Cid contentCid = Cid.decode("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"); int numProviders = 10; CompletableFuture> providersFuture = dht.findProviders(contentCid, node, numProviders); List providers = providersFuture.join(); System.out.println("Found " + providers.size() + " providers for " + contentCid); // Bootstrap the routing table with seed nodes List bootstrapNodes = List.of( new MultiAddress("/ip4/147.75.83.83/tcp/4001/p2p/QmW9m57aiBDHAkKj9nmFSEn7ZqrcF1fZS4bipsTCHburei") ); int connected = dht.bootstrapRoutingTable(node, bootstrapNodes, addr -> true); System.out.println("Connected to " + connected + " bootstrap nodes"); // Perform periodic bootstrap to refresh routing table dht.bootstrap(node); ``` -------------------------------- ### DHT Operations Source: https://context7.com/peergos/nabu/llms.txt APIs for interacting with the Kademlia Distributed Hash Table (DHT) for peer discovery and content routing. ```APIDOC ## GET /api/v0/dht/findprovs ### Description Finds providers for a given Content Identifier (CID). ### Method GET ### Endpoint /api/v0/dht/findprovs ### Parameters #### Query Parameters - **arg** (string) - Required - The Content Identifier (CID) to find providers for. - **num-providers** (integer) - Optional - The desired number of providers to retrieve. Defaults to 5. ### Response *Note: The response format for this endpoint is not explicitly detailed in the provided text, but it typically returns a list of peer information for providers.* ``` -------------------------------- ### Add Nabu Dependency to Maven Project Source: https://github.com/peergos/nabu/blob/master/README.md This snippet shows how to add the Nabu library as a dependency to your Maven project by configuring JitPack as a repository. Replace '$LATEST_VERSION' with the actual latest version of Nabu. ```xml jitpack.io https://jitpack.io com.github.peergos nabu $LATEST_VERSION ``` -------------------------------- ### HTTP API Server Usage Source: https://context7.com/peergos/nabu/llms.txt Interact with the embedded IPFS node using Kubo-compatible HTTP API endpoints. ```APIDOC ## HTTP API Server Usage ### Description Interact with the embedded IPFS node using Kubo-compatible HTTP API endpoints. ### Base URL `http://localhost:5001/api/v0/` ### Endpoints #### GET /id ##### Description Gets the node's identity. ##### Request Example ```bash curl "http://localhost:5001/api/v0/id" ``` ##### Response Example ```json { "ID": "QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF" } ``` #### POST /block/put ##### Description Stores a block. ##### Query Parameters - **format** (string) - Optional - The format of the block (e.g., `raw`). ##### Request Example ```bash echo "Hello IPFS" | curl -X POST -F file=@- \ "http://localhost:5001/api/v0/block/put?format=raw" ``` ##### Response Example ```json { "Hash": "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e" } ``` #### GET /block/get ##### Description Retrieves a block. ##### Query Parameters - **arg** (string) - Required - The CID of the block to retrieve. ##### Request Example ```bash curl "http://localhost:5001/api/v0/block/get?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" ``` ##### Response Example ``` (raw block bytes) ``` #### GET /block/has ##### Description Checks if a block exists. ##### Query Parameters - **arg** (string) - Required - The CID of the block to check. ##### Request Example ```bash curl "http://localhost:5001/api/v0/block/has?arg=QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" ``` ##### Response Example ``` true ``` ``` -------------------------------- ### IPNS Record Publishing in Java Source: https://context7.com/peergos/nabu/llms.txt Enables the publishing of mutable IPNS records, mapping peer IDs to content identifiers or other data. This involves using a private key for signing, specifying the value to publish, a sequence number, and a time-to-live. It utilizes the DHT for distribution and provides feedback on the number of peers the record was published to. ```java import io.libp2p.core.crypto.PrivKey; import io.libp2p.core.PeerId; import java.util.Optional; import java.util.concurrent.CompletableFuture; // Assuming 'builder' is initialized and has a getPrivateKey() method // PrivKey privKey = builder.getPrivateKey(); // Placeholder for PrivKey generation or retrieval // For demonstration, let's assume privKey is obtained elsewhere // PrivKey privKey = ...; // Value to publish (typically a CID path, but can be any data) byte[] value = "/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG".getBytes(); // Sequence number (increment for each update) long sequence = 1; // Time-to-live in hours int hoursTtl = 24; // Optional extra data for application-specific metadata Optional extraDataKey = Optional.of("version"); // Assuming Cborable and CborString are available types // Optional extraData = Optional.of(new CborString("1.0")); Optional extraData = Optional.of("1.0"); // Simplified for example // Assuming 'ipfs' is an initialized instance of your IPFS client // CompletableFuture publishFuture = ipfs.publishValue( // privKey, // value, // extraDataKey, // extraData, // sequence, // hoursTtl // ); // Placeholder for actual publish call CompletableFuture publishFuture = CompletableFuture.completedFuture(10); int peerCount = publishFuture.join(); System.out.println("Published IPNS record to " + peerCount + " peers"); // The record is now resolvable at /ipns/ // Assuming PeerId class is available // PeerId publisherId = PeerId.fromPubKey(privKey.publicKey()); // System.out.println("Record published at: /ipns/" + publisherId.toBase58()); ``` -------------------------------- ### IPNS Operations Source: https://context7.com/peergos/nabu/llms.txt APIs for resolving IPNS (InterPlanetary Name System) names. ```APIDOC ## GET /api/v0/ipns/get ### Description Resolves an IPNS name to its associated data. ### Method GET ### Endpoint /api/v0/ipns/get ### Parameters #### Query Parameters - **arg** (string) - Required - The IPNS name to resolve. ### Response #### Success Response (200) - **sig** (string) - The digital signature associated with the IPNS record. - **data** (string) - The resolved data associated with the IPNS name. #### Response Example ```json { "sig": "a1b2c3...", "data": "d4e5f6..." } ``` ``` -------------------------------- ### Add Nabu as Gradle Dependency Source: https://context7.com/peergos/nabu/llms.txt Provides instructions for adding the Nabu library as a dependency to a Gradle project. This involves specifying the JitPack repository and the dependency coordinates in the build.gradle file. This is an alternative to Maven for managing project dependencies. ```groovy repositories { maven { url 'https://jitpack.io' } } dependencies { implementation 'com.github.peergos:nabu:v0.9' } ``` -------------------------------- ### Add Nabu as Maven Dependency Source: https://context7.com/peergos/nabu/llms.txt Instructions for adding the Nabu library as a dependency to a Maven project. This involves configuring the JitPack repository in the pom.xml file. Ensure your project is set up with Maven to utilize this dependency management. ```xml jitpack.io https://jitpack.io com.github.peergos nabu v0.9 ``` -------------------------------- ### Block Storage Operations Source: https://context7.com/peergos/nabu/llms.txt Operations for storing, retrieving, checking existence, and removing blocks in the local blockstore. Supports different codec formats like Raw and DagCbor. ```APIDOC ## Block Storage Operations ### Description Store and manage blocks in the local blockstore with different codec formats. ### Methods - **put**: Stores a block with a specified codec. - **has**: Checks if a block exists in the store. - **get**: Retrieves a block from the store. - **rm**: Removes a block from the store. - **refs**: Lists all local blocks. - **count**: Gets the total count of blocks in the store. ### Request Example (Storing Raw Data) ```java byte[] rawData = "Hello, IPFS!".getBytes(); CompletableFuture cidFuture = blockstore.put(rawData, Cid.Codec.Raw); Cid rawCid = cidFuture.join(); ``` ### Response Example (Storing Raw Data) ```json { "cid": "" } ``` ### Request Example (Retrieving Data) ```java CompletableFuture> dataFuture = blockstore.get(rawCid); Optional data = dataFuture.join(); ``` ### Response Example (Retrieving Data) ```java "Hello, IPFS!" ``` ``` -------------------------------- ### Block Retrieval from IPFS Network Source: https://context7.com/peergos/nabu/llms.txt This endpoint allows retrieving blocks from the IPFS network, either from local storage or remote peers. It uses the Bitswap protocol and supports specifying target peers and whether to add retrieved blocks to the local blockstore. ```APIDOC ## Block Retrieval from IPFS Network ### Description Retrieve content-addressed blocks from local storage or remote peers using Bitswap protocol. ### Method POST (implicitly, as it's an operation on an existing instance) ### Endpoint N/A (Operation on an `EmbeddedIpfs` instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Parameters are passed as method arguments) ### Request Example ```java import io.ipfs.cid.Cid; import org.peergos.*; import org.peergos.protocol.bitswap.Want; import io.libp2p.core.PeerId; import java.util.*; // Create a want list with the CIDs to retrieve List wants = Arrays.asList( new Want(Cid.decode("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG")), new Want(Cid.decode("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi")) ); // Optionally specify peer IDs to retrieve from (empty set = query DHT for providers) Set retrieveFrom = Set.of( PeerId.fromBase58("QmVdFZgHnEgcedCS2G2ZNiEN59LuVrnRm7z3yXtEBv2XiF") ); // Retrieve blocks and add to local blockstore boolean addToLocal = true; try { List blocks = ipfs.getBlocks(wants, retrieveFrom, addToLocal); for (HashedBlock block : blocks) { System.out.println("Retrieved CID: " + block.hash); System.out.println("Block size: " + block.block.length + " bytes"); System.out.println("Data: " + new String(block.block)); } } catch (Exception e) { System.err.println("Failed to retrieve blocks: " + e.getMessage()); } // For single block retrieval with authentication Optional authToken = Optional.of("bat-token-here"); Want authenticatedWant = new Want( Cid.decode("QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"), authToken ); List authBlocks = ipfs.getBlocks( List.of(authenticatedWant), Collections.emptySet(), true ); ``` ### Response #### Success Response (200) - **blocks** (List) - A list of retrieved blocks, where each `HashedBlock` contains the CID (hash) and the block data. #### Response Example ```json [ { "hash": "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG", "block": "aGVsbG8gd29ybGQ=" } ] ``` ```