kubo/client/rpc
Hector Sanjuan a673c2ec95
fix: Provide according to Reprovider.Strategy (#10886)
* Provide according to strategy

Updates boxo to a version with the changes from https://github.com/ipfs/boxo/pull/976, which decentralize the providing responsibilities (from a central providing.Exchange to blockstore, pinner, mfs).

The changes consist in initializing the Pinner, MFS and the blockstore with the provider.System, which is created first.

Since the provider.System is created first, the reproviding KeyChanFunc is set
later when we can create it once we have the Pinner, MFS and the blockstore.

Some additional work applies to the Add() workflow. Normally, blocks would get provided at the Blockstore or the Pinner, but when adding blocks AND a "pinned" strategy is used, the blockstore does not provide, and the
pinner does not traverse the DAG (and thus doesn't provide either), so we need to provide directly from the Adder. This is resolved by wrapping the DAGService in a "providingDAGService" which provides every added block, when using the "pinned" strategy.

`ipfs --offline add` when the ONLINE daemon is running will now announce blocks per the chosen strategy, where before it did not announce them. This is documented in the changelog. A couple of releases ago, adding with `ipfs --offline add` was faster, but this is no longer the case so we are not incurring in any penalties by sticking to the fact that the daemon is online and has a providing strategy that we follow.

Co-authored-by: gammazero <11790789+gammazero@users.noreply.github.com>
Co-authored-by: Marcin Rataj <lidel@lidel.org>
2025-08-08 10:56:44 +02:00
..
auth feat(rpc): Opt-in HTTP RPC API Authorization (#10218) 2023-11-17 01:29:29 +01:00
api_test.go fix: Provide according to Reprovider.Strategy (#10886) 2025-08-08 10:56:44 +02:00
api.go chore: stop using go-homedir (#10568) 2024-11-05 07:45:11 -08:00
apifile.go feat: Support storing UnixFS 1.5 Mode and ModTime (#10478) 2024-08-21 02:02:46 +02:00
block.go chore: clean migration 2023-11-29 12:29:59 +01:00
dag.go chore: clean migration 2023-11-29 12:29:59 +01:00
errors_test.go client/rpc: rename package name to match rpc and edit migration story 2023-05-31 15:40:00 +02:00
errors.go chore: fix some typos (#10396) 2024-06-03 17:17:58 +02:00
key.go feat: ipfs key sign|verify (#10235) 2023-12-04 09:51:26 +01:00
name.go chore: clean migration 2023-11-29 12:29:59 +01:00
object.go core/commands!: remove deprecated object APIs (#10375) 2024-03-22 09:32:30 +01:00
path.go chore: update boxo for structification of ImmutablePath 2023-10-09 09:44:39 +02:00
pin.go refactor(cmds): do not return errors embedded in result type (#10527) 2024-12-03 20:15:33 +01:00
pubsub.go chore: clean migration 2023-11-29 12:29:59 +01:00
README.md docs: replace outdated package paths described in rpc README (#10505) 2024-09-05 23:20:08 +02:00
request.go client/rpc: rename package name to match rpc and edit migration story 2023-05-31 15:40:00 +02:00
requestbuilder.go fix: use %-encoded headers in most compatible way 2023-08-22 15:43:01 +02:00
response.go style: gofumpt and godot [skip changelog] (#10081) 2023-08-17 14:02:08 +02:00
routing.go core: deprecate CoreAPI.Dht, introduce CoreAPI.Routing 2024-02-07 10:47:30 +01:00
swarm.go chore: clean migration 2023-11-29 12:29:59 +01:00
unixfs.go refactor(cmds): do not return errors embedded in result type (#10527) 2024-12-03 20:15:33 +01:00

coreiface.CoreAPI over http rpc

IPFS CoreAPI implementation using HTTP API

This package implements coreiface.CoreAPI over the HTTP API.

Documentation

https://pkg.go.dev/github.com/ipfs/kubo/client/rpc

Example

Pin file on your local IPFS node based on its CID:

package main

import (
	"context"
	"fmt"

	"github.com/ipfs/boxo/path"
	"github.com/ipfs/go-cid"
	"github.com/ipfs/kubo/client/rpc"
)

func main() {
	// "Connect" to local node
	node, err := rpc.NewLocalApi()
	if err != nil {
		fmt.Println(err)
		return
	}
	// Pin a given file by its CID
	ctx := context.Background()
	c, err := cid.Decode("bafkreidtuosuw37f5xmn65b3ksdiikajy7pwjjslzj2lxxz2vc4wdy3zku")
	if err != nil {
		fmt.Println(err)
		return
	}
	p := path.FromCid(c)
	err = node.Pin().Add(ctx, p)
	if err != nil {
		fmt.Println(err)
		return
	}
}