(ctx context.Context, path path.Path, opts ...caopts.RoutingProvideOption)
| 118 | } |
| 119 | |
| 120 | func (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 | |
| 163 | func provideKeysRec(ctx context.Context, prov node.DHTProvider, bs blockstore.Blockstore, cids []cid.Cid) error { |
| 164 | provided := cidutil.NewStreamingSet() |
nothing calls this directly
no test coverage detected