libp2p / libp2p/go-libp2p-pubsub

Add callback to signal successful publish

Open
#511 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
364
Forks
221
PR merge metrics
No merged PRs in 30d

Description

On several occasions, I have found myself wanting to know exactly when a particular call to `Topic.Publish` has written the message to the wire. This is either because of some business logic (e.g. wait until peers have been signaled before doing something) or because I want to pool the `[]byte` argument in high-throughput applications.

From an API perspective, this would ideally take the form of a `PubOpt`, allowing us to write:

```go
err := t.Publish(ctx, data, WithCallback(func(m *Message) {
pool.Put(m.Data) // sync.Pool
})
```

The main difficulty I'm seeing is that messages are fanned out to a number of peers via buffered channels, so this would likely require some kind of refcounting scheme to ensure the callback is not called prematurely.

Is this a sensible ask? Any recommendations?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Topic.Publish and the PubOpt API, then trace how messages are fanned out through buffered channels to peers. Determine how a callback can run only after the message is written to the wire for all relevant peers, using refcounting or an equivalent lifecycle mechanism. Done means callers can safely pool the []byte data without premature reuse.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.