Client: Add never returning

Hello,

I am trying to add a file using the ipfs-cluster client (github.com/ipfs/ipfs-cluster/api/rest/client) and am unsure on how the Add method actually works. When running a local cluster of 4 nodes, the Add function does not returned (I waited until 10 minutes), but I shortly get an output in the AddedOutput. I guess I am missing something and not using the API correctly.

func AddFile(c client.Client, path string) string {
	ctx := context.Background()

	out := make(chan *api.AddedOutput)
	paths := []string{path}
	go c.Add(ctx, paths, api.DefaultAddParams(), out)
	ao := <-out
	return ao.Cid.String()
}

In the Add implementation, the following is mentioned:

The output channel will receive regular updates as the adding process progresses.

  1. What do these updates mean, and when are they sent ?
  2. When exactly is the Add function supposed to return ?
  3. Is there a detailed doc of the ipfs-cluster Add process ?

Thanks in advance for your answers

Hi,

you are creating a channel with no capacity and you are only reading one value out of it. Iā€™m guessing things are stuck because the other side cannot put more things in the channel.

I have to redirect you here:

  • Make a channel with some buffer capacity
  • for-loop reading from the channel to receive all the progress updates until the channel is closed (adding finished or an error happened).
  • The last message from the channel will always be the final root CID.

Another example of usage here: https://github.com/hsanjuan/twitter-pinbot/blob/master/main.go#L255

Let me know if I can be of more help.

1 Like

Amazing! Thank you very much!

Forgot to add, you get one AddedOutput object per file/folder added.