### Clone Kubo Repository and Navigate to Example Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md Clone the Kubo repository and navigate to the example directory to begin the tutorial. Ensure you have Git installed. ```bash git clone https://github.com/ipfs/kubo.git cd kubo/docs/examples/kubo-as-a-library ``` -------------------------------- ### Run IPFS Integration Test Setup Source: https://github.com/ipfs/kubo/blob/master/test/3nodetest/README.md Execute these commands in sequence to set up and start the IPFS test environment. Ensure Docker, fig, and Go are installed and the IPFS image is named correctly. ```bash make setup fig build fig up ``` -------------------------------- ### Run the Kubo as a Library Example Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md Execute the main Go program to run the Kubo as a library example. This command assumes you are in the example directory. ```bash go run main.go ``` -------------------------------- ### Install go-sleep Source: https://github.com/ipfs/kubo/blob/master/test/dependencies/go-sleep/README.md Use 'go install' to install the go-sleep utility. Ensure your Go environment is set up correctly. ```sh go install github.com/chriscool/go-sleep ``` -------------------------------- ### Dual DHT Configuration Example Source: https://github.com/ipfs/kubo/blob/master/docs/delegated-routing.md This JSON configuration demonstrates a dual DHT setup with parallel routers, including options for strict and lenient error handling. ```json "Routing": { "Type": "custom", "Routers": { "dht-lan": { "Type": "dht", "Parameters": { "Mode": "server", "PublicIPNetwork": false } }, "dht-wan": { "Type": "dht", "Parameters": { "Mode": "auto", "PublicIPNetwork": true } }, "parallel-dht-strict": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan" }, { "RouterName": "dht-wan" } ] } }, "parallel-dht": { "Type": "parallel", "Parameters": { "Routers": [ { "RouterName": "dht-lan", "IgnoreError": true }, { "RouterName": "dht-wan" } ] } } }, "Methods": { "provide": { "RouterName": "dht-wan" }, "find-providers": { "RouterName": "parallel-dht-strict" }, "find-peers": { "RouterName": "parallel-dht-strict" }, "get-ipns": { "RouterName": "parallel-dht" }, "put-ipns": { "RouterName": "parallel-dht" } } } ``` -------------------------------- ### Install Kubo on Solus Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the eopkg package manager on Solus. ```bash sudo eopkg install kubo ``` -------------------------------- ### Install Kubo on openSUSE Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the zypper package manager on openSUSE. ```bash zypper install kubo ``` -------------------------------- ### Install Kubo on Ubuntu Source: https://github.com/ipfs/kubo/blob/master/README.md Use the provided PPA to install Kubo on Ubuntu systems. ```bash sudo apt install ipfs-kubo ``` -------------------------------- ### Install Build Dependencies and Build Kubo with Make Source: https://github.com/ipfs/kubo/blob/master/docs/windows.md Installs necessary tools like git, make, and unzip using pacman, fetches the Kubo source, and builds the project. Ensure MSYS2 is installed and its bin directory is in the PATH. ```bash SET PATH=%PATH%;\msys64\usr\bin pacman --noconfirm -S git make unzip go get -u github.com/ipfs/kubo cd %GOPATH%\src\github.com\ipfs\kubo make install %GOPATH%\bin\ipfs.exe version --all ``` -------------------------------- ### Install Kubo on Gentoo Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the emerge package manager on Gentoo. ```bash emerge -a net-p2p/kubo ``` -------------------------------- ### Install Kubo on Nix Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the nix-env command on Nix systems. ```bash nix-env -i kubo ``` -------------------------------- ### Install Kubo on Guix Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the guix package manager. ```bash guix install kubo ``` -------------------------------- ### Install IPFS Kubo with Cygwin Source: https://github.com/ipfs/kubo/blob/master/docs/windows.md This script sets up the build environment, clones the Kubo repository, builds the project, and verifies the installation. ```bash SET PATH=%PATH%;\cygwin64\bin mkdir %GOPATH%\src\github.com\ipfs cd %GOPATH%\src\github.com\ipfs git clone https://github.com/ipfs/kubo.git cd %GOPATH%\src\github.com\ipfs\kubo make install %GOPATH%\bin\ipfs.exe version --all ``` -------------------------------- ### Install Kubo on Windows with Scoop Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the Scoop package manager on Windows. ```bash scoop install kubo ``` -------------------------------- ### Clone Kubo and Build Source: https://github.com/ipfs/kubo/blob/master/docs/developer-guide.md Clone the Kubo repository, navigate into the directory, and build the ipfs binary. This is the initial setup for local development. ```bash git clone https://github.com/ipfs/kubo.git cd kubo make build ``` -------------------------------- ### Install Kubo System-Wide Source: https://github.com/ipfs/kubo/blob/master/docs/developer-guide.md Install the built ipfs binary to your system's PATH, typically in $GOPATH/bin. This allows you to run the 'ipfs' command from anywhere. ```bash make install ``` -------------------------------- ### Build Kubo from Source Source: https://github.com/ipfs/kubo/blob/master/README.md Clones the Kubo repository, navigates into the directory, and builds the IPFS binary. This method requires Go to be installed. ```bash git clone https://github.com/ipfs/kubo.git cd kubo make build # creates cmd/ipfs/ipfs make install # installs to $GOPATH/bin/ipfs ``` -------------------------------- ### Build and test IPFS with CMD Source: https://github.com/ipfs/kubo/blob/master/docs/windows.md Installs the IPFS binary with the commit hash embedded in the build flags and then tests the installed binary. ```bat go install -ldflags="-X \"github.com/ipfs/kubo\".CurrentCommit=%SHA%" %GOPATH%\bin\ipfs.exe version --all ``` -------------------------------- ### Enable and Start Kubo IPFS Services Source: https://github.com/ipfs/kubo/blob/master/docs/p2p-tunnels.md Use these systemctl commands to enable and start the IPFS service and its associated path unit for persistent operation. ```bash $ systemctl --user enable ipfs.service $ systemctl --user enable ipfs-p2p-tunnel.path $ systemctl --user start ipfs.service ``` -------------------------------- ### Install Kubo on Arch Linux Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the pacman package manager on Arch Linux. ```bash pacman -S kubo ``` -------------------------------- ### Install Kubo on macOS with Homebrew Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the Homebrew package manager on macOS. ```bash brew install ipfs ``` -------------------------------- ### Build and test IPFS with PowerShell Source: https://github.com/ipfs/kubo/blob/master/docs/windows.md Installs the IPFS binary with the commit hash embedded in the build flags, copies the executable to the bin directory, and tests the installed binary. ```powershell go install -ldflags="-X \"github.com/ipfs/kubo\".CurrentCommit=$env:SHA" cp ./ipfs.exe $env:GOPATH/bin/ipfs.exe -force . $env:GOPATH/bin/ipfs.exe version --all ``` -------------------------------- ### Quick Start: Test P2P Tunnel with Netcat (Client) Source: https://github.com/ipfs/kubo/blob/master/docs/p2p-tunnels.md On the client, forward a local port through P2P to the server and connect with netcat. ```bash ipfs p2p forward /x/test /ip4/127.0.0.1/tcp/9998 /p2p/$SERVER_ID nc 127.0.0.1 9998 ``` -------------------------------- ### Install Kubo on Fedora Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the dnf package manager from the specified COPR repository on Fedora. ```bash dnf install kubo ``` -------------------------------- ### Denylist File Format Examples Source: https://github.com/ipfs/kubo/blob/master/docs/content-blocking.md Examples of content paths in a denylist file. Paths with unicode and whitespace need to be percent-encoded. ```text /ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR ``` ```text /ipfs/bafybeihfg3d7rdltd43u3tfvncx7n5loqofbsobojcadtmokrljfthuc7y/927%20-%20Standards/927%20-%20Standards.png ``` -------------------------------- ### Start IPFS Daemon Source: https://github.com/ipfs/kubo/blob/master/README.md Starts the IPFS daemon in the background, making the node available on the network. Ensure initialization is done first. ```bash ipfs daemon & Daemon is ready ``` -------------------------------- ### Quick Start: Test P2P Tunnel with Netcat (Server) Source: https://github.com/ipfs/kubo/blob/master/docs/p2p-tunnels.md On the server, listen on a P2P protocol and forward to a local netcat listener. ```bash ipfs p2p listen /x/test /ip4/127.0.0.1/tcp/9999 nc -l -p 9999 ``` -------------------------------- ### Install Kubo on macOS with MacPorts Source: https://github.com/ipfs/kubo/blob/master/README.md Install Kubo using the MacPorts package manager on macOS. ```bash sudo port install ipfs ``` -------------------------------- ### Verify Build Source: https://github.com/ipfs/kubo/blob/master/docs/developer-guide.md After building, verify the installation by checking the ipfs binary version. This confirms the build process was successful. ```bash ./cmd/ipfs/ipfs version ``` -------------------------------- ### Install In-tree Plugin Source: https://github.com/ipfs/kubo/blob/master/docs/plugins.md Copy a built plugin to the IPFS path and ensure it is executable. This makes the plugin available to the IPFS daemon. ```bash kubo$ mkdir -p ~/.ipfs/plugins/ kubo$ cp plugin/plugins/git.so ~/.ipfs/plugins/ kubo$ chmod +x ~/.ipfs/plugins/git.so ``` -------------------------------- ### Example IPFS Peer Addresses Source: https://github.com/ipfs/kubo/blob/master/docs/file-transfer.md This is an example output from `ipfs routing findpeer`. It shows various address formats including localhost, LAN, and potential external IP addresses. ```text /ip4/127.0.0.1/tcp/4001 /ip4/127.0.0.1/udp/4001/quic-v1 /ip4/192.168.2.133/tcp/4001 /ip4/192.168.2.133/udp/4001/quic-v1 /ip4/88.157.217.196/tcp/63674 /ip4/88.157.217.196/udp/63674/quic-v1 ``` -------------------------------- ### Example Bootstrap Node Addition Source: https://github.com/ipfs/kubo/blob/master/docs/experimental-features.md An example of adding a specific bootstrap node using its multiaddress. This is used to connect to peers within a private network. ```bash ipfs bootstrap add /ip4/104.236.76.40/tcp/4001/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64 ``` -------------------------------- ### Enable Path Gateway Source: https://github.com/ipfs/kubo/blob/master/docs/config.md Configure a hostname to act as a path gateway. This example enables `http://ipfs.io/*` and requires `/ipfs` and `/ipns` paths to be set. ```json "Gateway": { "PublicGateways": { "ipfs.io": { "UseSubdomains": false, "Paths": ["/ipfs", "/ipns"] } } } ``` -------------------------------- ### Configure Public Gateway Paths Source: https://github.com/ipfs/kubo/blob/master/docs/config.md Specify an array of paths that should be exposed on a given hostname for the public gateway. This example enables `http://example.com/ipfs/*` but not `http://example.com/ipns/*`. ```json { "Gateway": { "PublicGateways": { "example.com": { "Paths": ["/ipfs"] } } } } ``` -------------------------------- ### Get IPFS CLI Help Source: https://github.com/ipfs/kubo/blob/master/cmd/ipfs/dist/README.md Display all available commands and options for the IPFS command line tool. Use this to explore further functionalities. ```sh ipfs --help ``` -------------------------------- ### Install IPFS CLI Binary Source: https://github.com/ipfs/kubo/blob/master/cmd/ipfs/dist/README.md Move the IPFS binary to a directory in your system's PATH for global access. Ensure you have the necessary permissions. ```sh sudo mv ipfs /usr/local/bin/ipfs ``` -------------------------------- ### Pebble Datastore Configuration Example Source: https://github.com/ipfs/kubo/blob/master/docs/datastores.md This JSON snippet shows the basic configuration for the 'pebbleds' datastore type, specifying the path where the Pebble store will be located within the repository. ```json { "type": "pebbleds", "path": "", } ``` -------------------------------- ### Initialize IPFS, Launch Daemon, and Mount Separately Source: https://github.com/ipfs/kubo/blob/master/test/sharness/README.md Demonstrates the sequence of initializing IPFS, launching the daemon, and then mounting the filesystem. This allows for tests to be run at different stages (inited but not running, running but not mounted, mounted). Remember to kill the daemon. ```shell test_init_ipfs # tests inited but not running here test_launch_ipfs_daemon # tests running but not mounted here test_mount_ipfs # tests mounted here # don't forget to kill the daemon!! test_kill_ipfs_daemon ``` -------------------------------- ### Prepare and Set Up Kubo Plugins Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md This Go code snippet demonstrates how to prepare and set up the necessary plugins for a Kubo node. It's a prerequisite for initializing an IPFS node. ```go plugins := []plugin.Plugin{ &ipns.Plugin{}, &http.Plugin{}, &gateway.Gateway{}, &config.Plugin{}, &metrics.Plugin{}, &pprof.Plugin{}, &leveldb.Storage{}, &badger.Storage{}, &unixfs.UnixFS{}, &oldcmds.Commands{}, &mocknet.Mocknet{}, &ipld.Plugin{}, } ctx, cancel := context.WithCancel(context.Background()) defer cancel() // Prepare the node configuration conf := &config.Config{ Addresses: config.Addresses{ API: "/ip4/0.0.0.0/tcp/0", Gateway: "/ip4/0.0.0.0/tcp/0", }, } // Set up the plugins setup := &core.BuildNode setup.Online = true setup.Offline = false setup.Plugins = plugins setup.Config = conf // Create a temporary directory for the IPFS repository fs := afero.NewMemMapFs() repoPath := "/tmp/test-repo" err := ipfs.Setup(fs, repoPath, setup) if err != nil { panic(err) } ``` -------------------------------- ### Install macFUSE on macOS Source: https://github.com/ipfs/kubo/blob/master/docs/fuse.md Installs macFUSE on macOS using Homebrew. After installation, system settings must be updated to allow the kernel extension. ```sh brew install --cask macfuse ``` -------------------------------- ### Launch IPFS Daemon, Mount, and Test Command Source: https://github.com/ipfs/kubo/blob/master/test/sharness/README.md Initialize, start the IPFS daemon, mount the filesystem, and then execute a command like 'ipfs add --help'. Ensure the daemon is killed afterwards. ```shell test_launch_ipfs_daemon_and_mount test_expect_success "'ipfs add --help' succeeds" ' ipfs add --help >actual ' # other tests here... # don't forget to kill the daemon!! test_kill_ipfs_daemon ``` -------------------------------- ### Prepare a File for IPFS Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md This Go code prepares a file named 'hello.txt' with content 'Hello IPFS!' to be added to the IPFS repository. It uses afero.NewMemMapFs for an in-memory filesystem. ```go fileContent := "Hello IPFS!" fileName := "hello.txt" // Create a file in memory file := fs.NewFile(fileName) _, err := file.Write([]byte(fileContent)) if err != nil { panic(err) } // Add the file to IPFS fileAdded, err := ipfsCore.Unixfs().Add(ctx, io.NopCloser(bytes.NewReader([]byte(fileContent)))) if err != nil { panic(err) } fmt.Printf("Added file to IPFS with CID %s\n", fileAdded.String()) ``` -------------------------------- ### Install fuse3 on Fedora Source: https://github.com/ipfs/kubo/blob/master/docs/fuse.md Installs the fuse3 package on Fedora systems using dnf. ```sh sudo dnf install fuse3 ``` -------------------------------- ### Install fuse3 on Arch Linux Source: https://github.com/ipfs/kubo/blob/master/docs/fuse.md Installs the fuse3 package on Arch Linux systems using pacman. ```sh sudo pacman -S fuse3 ``` -------------------------------- ### AutoConf Usage Example Source: https://github.com/ipfs/kubo/blob/master/docs/config.md Demonstrates how to configure AutoConf to fetch network settings from a remote URL and use 'auto' placeholders for bootstrap peers, DNS resolvers, and delegated routing. ```json { "AutoConf": { "URL": "https://example.com/autoconf.json", "Enabled": true, "RefreshInterval": "24h" }, "Bootstrap": ["auto"], "DNS": { "Resolvers": { ".": ["auto"], "eth.": ["auto"], "custom.": ["https://dns.example.com/dns-query"] } }, "Routing": { "DelegatedRouters": ["auto", "https://router.example.org/routing/v1"] } } ``` -------------------------------- ### Construct and Initialize an IPFS Node Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md This Go code demonstrates constructing and initializing an IPFS node instance using the core API. The node starts running as soon as the instance is created. ```go node, err := core.NewNode(ctx, setup) if err != nil { panic(err) } // The node is now running fmt.Println("IPFS node is running") // Use the node ipfsCore := node.Ipfs // Close the node when done // defer node.Close() ``` -------------------------------- ### Build Kubo with Preloaded Plugins Source: https://github.com/ipfs/kubo/blob/master/docs/plugins.md Build the Kubo binary with specific plugins preloaded. This bundles the plugins directly into the binary. ```bash kubo$ make build ``` -------------------------------- ### Prepare Project Before Submission Source: https://github.com/ipfs/kubo/blob/master/AGENTS.md Sequence of commands to run before submitting changes. This includes tidying Go modules, formatting code, building the project, linting, and running all tests. ```bash make mod_tidy go fmt ./... make build make -O test_go_lint go test ./... (or the relevant subset) ``` -------------------------------- ### PR Closing References Example Source: https://github.com/ipfs/kubo/blob/master/AGENTS.md Use this format in your PR description to close issues in the ipfs/kubo repository. ```markdown ## References - Closes https://github.com/ipfs/kubo/issues/1234 - Closes https://github.com/ipfs/kubo/issues/5678 - https://discuss.ipfs.tech/t/related-topic/999 ``` -------------------------------- ### Display IPFSWatch Help Information Source: https://github.com/ipfs/kubo/blob/master/cmd/ipfswatch/README.md Use the --help flag to view all available options and their descriptions for the ipfswatch command. This includes options for specifying the directory to watch and the IPFS repository path. ```bash λ. ipfswatch --help -path=".": the path to watch -repo="": IPFS_PATH to use ``` -------------------------------- ### Prepare a Directory for IPFS Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md This Go code prepares a directory structure in memory, including a file named 'config.json', to be added to IPFS. It uses afero.NewMemMapFs for the filesystem. ```go dirName := "example-folder" fileNameInDir := "config.json" fileContentInDir := "{\"setting\": \"value\"}" // Create a directory in memory err := fs.MkdirAll(dirName, os.ModePerm) if err != nil { panic(err) } // Create a file inside the directory fileInDir := fs.NewFile(filepath.Join(dirName, fileNameInDir)) _, err = fileInDir.Write([]byte(fileContentInDir)) if err != nil { panic(err) } // Add the directory to IPFS dirAdded, err := ipfsCore.Unixfs().Add(ctx, io.NopCloser(bytes.NewReader([]byte(fileContentInDir)))) // Note: This line seems to add the file content, not the directory structure itself. The example likely intends to add the directory. if err != nil { panic(err) } fmt.Printf("Added directory to IPFS with CID %s\n", dirAdded.String()) ``` -------------------------------- ### Example Blocked CID Error Source: https://github.com/ipfs/kubo/blob/master/docs/content-blocking.md CLI and Gateway users will receive this error when requesting content that is blocked by a denylist. ```text Error: /ipfs/QmQvjk82hPkSaZsyJ8vNER5cmzKW7HyGX5XVusK7EAenCN is blocked and cannot be provided ``` -------------------------------- ### Run IPFS Daemon with Timeout Source: https://github.com/ipfs/kubo/blob/master/docs/developer-guide.md Start the IPFS daemon with a specified timeout to ensure it shuts down promptly. This is recommended for experiments. ```bash timeout 60s ipfs daemon ``` -------------------------------- ### Create an IPFS Repository Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md This Go code snippet shows how to create an IPFS repository using afero.NewMemMapFs for an in-memory filesystem. This is part of setting up an ephemeral node. ```go fs := afero.NewMemMapFs() repoPath := "/tmp/test-repo" err := ipfs.Setup(fs, repoPath, setup) if err != nil { panic(err) } ``` -------------------------------- ### Configure AutoNAT Service Mode Source: https://github.com/ipfs/kubo/blob/master/docs/config.md Set the operational mode for the libp2p AutoNAT service. This example shows how to explicitly disable the service. ```json { "AutoNAT": { "ServiceMode": "disabled" } } ``` -------------------------------- ### Prepare IPFS FUSE mountpoints Source: https://github.com/ipfs/kubo/blob/master/docs/fuse.md Creates the default directories for IPFS, IPNS, and MFS FUSE mounts and sets ownership to the current user. These directories can be configured in Kubo's settings. ```sh # make the directories sudo mkdir /ipfs /ipns /mfs # chown them so ipfs can use them without root permissions sudo chown /ipfs /ipns /mfs ``` -------------------------------- ### IPNS DelegatedPublishers Example: Auto Configuration Source: https://github.com/ipfs/kubo/blob/master/docs/config.md Configures delegated publishers to automatically load from AutoConf when enabled. This setting is part of the default configuration. ```json ["auto"] ``` -------------------------------- ### Go-sleep Usage Example Source: https://github.com/ipfs/kubo/blob/master/test/dependencies/go-sleep/README.md Demonstrates how to use go-sleep to pause execution for a specified duration, such as 100 milliseconds. The output shows the real, user, and system time taken for the operation. ```sh > go-sleep Usage: go-sleep Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". See https://godoc.org/time#ParseDuration for more. > time go-sleep 100ms real 0m0.104s user 0m0.000s sys 0m0.007s ``` -------------------------------- ### Get a File Back from IPFS Source: https://github.com/ipfs/kubo/blob/master/docs/examples/kubo-as-a-library/README.md This Go code retrieves a file from IPFS using its CID. It then writes the file content to the local filesystem. ```go fileToGet := "example-folder/QmV9tSDx9UiPeWExXEeH6aoDvmihvx6jD5eLb4jbTaKGps" // Get the file back from IPFS fileReader, err := ipfsCore.Unixfs().Get(ctx, path.Path(fileToGet)) if err != nil { panic(err) } // Write the file to your local filesystem outputFile, err := fs.Create(fileToGet) if err != nil { panic(err) } _, err = io.Copy(outputFile, fileReader) if err != nil { panic(err) } fmt.Printf("Got file back from IPFS (IPFS path: %s) and wrote it to %s\n", fileToGet, fileToGet) ``` -------------------------------- ### Check for fuse Group Presence Source: https://github.com/ipfs/kubo/blob/master/docs/fuse.md Determine if the 'fuse' group is present on your system. This group is often created during fuse installation and is relevant for user permissions. ```sh sudo grep -q fuse /etc/group && echo fuse_group_present || echo fuse_group_missing ```