mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-04 07:48:00 +08:00
fix(docs): add explicit provide to kubo-as-a-library example
add Routing().Provide() call to ensure content is immediately discoverable via Amino DHT instead of relying on background reprovide which may not complete within the test timeout.
This commit is contained in:
parent
0c79aab6e6
commit
2d120faab3
@ -15,6 +15,7 @@ import (
|
||||
"github.com/ipfs/boxo/files"
|
||||
"github.com/ipfs/boxo/path"
|
||||
icore "github.com/ipfs/kubo/core/coreiface"
|
||||
"github.com/ipfs/kubo/core/coreiface/options"
|
||||
ma "github.com/multiformats/go-multiaddr"
|
||||
|
||||
"github.com/ipfs/kubo/config"
|
||||
@ -330,6 +331,17 @@ func main() {
|
||||
}
|
||||
fmt.Println("Connected to peers")
|
||||
|
||||
// By default, Kubo uses optimized background providing via Provide.DHT.SweepEnabled
|
||||
// (see https://github.com/ipfs/kubo/blob/master/docs/config.md#providedhtsweepenabled)
|
||||
// Since we don't want to wait for the automatic background provide to occur,
|
||||
// we do an ad-hoc provide to make the content immediately available on the Amino DHT.
|
||||
// We only provide the root CID (non-recursive) since that's all we need for this example.
|
||||
fmt.Println("Providing file to Amino DHT...")
|
||||
if err = ipfsA.Routing().Provide(ctx, peerCidFile, options.Routing.Recursive(false)); err != nil {
|
||||
panic(fmt.Errorf("could not provide file: %s", err))
|
||||
}
|
||||
fmt.Println("File provided to Amino DHT")
|
||||
|
||||
exampleCIDStr := peerCidFile.RootCid().String()
|
||||
|
||||
fmt.Printf("Fetching a file from the network with CID %s\n", exampleCIDStr)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user