MCPcopy
hub / github.com/ipfs/kubo / Provide

Method Provide

core/coreapi/routing.go:120–161  ·  view source on GitHub ↗
(ctx context.Context, path path.Path, opts ...caopts.RoutingProvideOption)

Source from the content-addressed store, hash-verified

118}
119
120func (api *RoutingAPI) Provide(ctx context.Context, path path.Path, opts ...caopts.RoutingProvideOption) error {
121 ctx, span := tracing.Span(ctx, "CoreAPI.DhtAPI", "Provide", trace.WithAttributes(attribute.String("path", path.String())))
122 defer span.End()
123
124 settings, err := caopts.RoutingProvideOptions(opts...)
125 if err != nil {
126 return err
127 }
128 span.SetAttributes(attribute.Bool("recursive", settings.Recursive))
129
130 err = api.checkOnline(false)
131 if err != nil {
132 return err
133 }
134
135 rp, _, err := api.core().ResolvePath(ctx, path)
136 if err != nil {
137 return err
138 }
139
140 c := rp.RootCid()
141
142 has, err := api.blockstore.Has(ctx, c)
143 if err != nil {
144 return err
145 }
146
147 if !has {
148 return fmt.Errorf("block %s not found locally, cannot provide", c)
149 }
150
151 if settings.Recursive {
152 err = provideKeysRec(ctx, api.provider, api.blockstore, []cid.Cid{c})
153 } else {
154 err = api.provider.StartProviding(false, c.Hash())
155 }
156 if err != nil {
157 return err
158 }
159
160 return nil
161}
162
163func provideKeysRec(ctx context.Context, prov node.DHTProvider, bs blockstore.Blockstore, cids []cid.Cid) error {
164 provided := cidutil.NewStreamingSet()

Callers

nothing calls this directly

Calls 8

coreMethod · 0.95
SpanFunction · 0.92
provideKeysRecFunction · 0.85
ResolvePathMethod · 0.65
StartProvidingMethod · 0.65
StringMethod · 0.45
HasMethod · 0.45
HashMethod · 0.45

Tested by

no test coverage detected