partialmessages

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PartialMessagesExtension

type PartialMessagesExtension[PeerState any] struct {
	Logger *slog.Logger

	// OnEmitGossip is called when the application should send gossip to the given
	// peers. The application SHOULD call PublishPartial to send partial
	// messages to these peers.
	//
	// The Application may persist some state in the peerStates map. The peers
	// to gossip to will have a zero-value PeerState in the map.
	OnEmitGossip func(topic string, groupID []byte, gossipPeers []peer.ID, peerStates map[peer.ID]PeerState)

	// OnIncomingRPC is called whenever we receive an encoded
	// partial message from a peer. This function MUST be fast and non-blocking.
	// If you need to do slow work (e.g. validation), dispatch the work to your
	// own goroutine.
	//
	// This function SHOULD update the peer's PeerState with the received
	// rpc.PartsMetadata and rpc.PartialMessage.
	//
	// An implementation may be able to infer some peer state from the
	// rpc.PartialMessage, for example:
	//  - peer's received state (we can infer they have a part if they have given it us)
	//  - our last update to a peer (they can infer an update if they have given us a part)
	//
	// If the rpc should be ignored, the application can leave peerStates unmodified
	OnIncomingRPC func(from peer.ID, peerStates map[peer.ID]PeerState, rpc *pb.PartialMessagesExtension) error

	// PeerInitiatedGroupLimitPerTopic limits the number of Group states all
	// peers can initialize per topic. A group state is initialized by a peer if
	// the peer's message marks the first time we've seen a group id.
	PeerInitiatedGroupLimitPerTopic int

	// PeerInitiatedGroupLimitPerTopicPerPeer limits the number of Group states
	// a single peer can initialize per topic. A group state is initialized by a
	// peer if the peer's message marks the first time we've seen a group id.
	PeerInitiatedGroupLimitPerTopicPerPeer int

	// GroupTTLByHeatbeat is how many heartbeats we store Group state for after
	// publishing a partial message for the group.
	GroupTTLByHeatbeat int
	// contains filtered or unexported fields
}

func (*PartialMessagesExtension[PeerState]) EmitGossip

func (e *PartialMessagesExtension[PeerState]) EmitGossip(topic string, peers []peer.ID)

func (*PartialMessagesExtension[PeerState]) HandleRPC

func (e *PartialMessagesExtension[PeerState]) HandleRPC(from peer.ID, rpc *pb.PartialMessagesExtension) error

func (*PartialMessagesExtension[PeerState]) Heartbeat

func (e *PartialMessagesExtension[PeerState]) Heartbeat()

func (*PartialMessagesExtension[PeerState]) Init

func (e *PartialMessagesExtension[PeerState]) Init(router Router) error

func (*PartialMessagesExtension[PeerState]) OnClosedOutboundStream

func (e *PartialMessagesExtension[PeerState]) OnClosedOutboundStream(id peer.ID)

func (*PartialMessagesExtension[PeerState]) PublishPartial

func (e *PartialMessagesExtension[PeerState]) PublishPartial(topic string, groupID []byte, publishActionsFn PublishActionsFn[PeerState]) error

type PartsMetadata

type PartsMetadata []byte

PartsMetadata returns metadata about the parts this partial message contains and, possibly implicitly, the parts it wants.

type PeerInfo

type PeerInfo struct {
	// If RequestedPartialMessage is false, the peer does not want encoded
	// partial messages. The encoded message in a PublishAction MUST be
	// empty for this peer. The implementation SHOULD still send relevant
	// partsMetadataToSend.
	RequestedPartialMessage bool
}

type PublishAction

type PublishAction struct {
	// EncodedPartialMessage is the encoded PartialMessage that will be sent to
	// this peer.
	EncodedPartialMessage []byte
	// EncodedPartsMetadata is the PartsMetadata that will be sent to this peer.
	EncodedPartsMetadata []byte

	// Err signals an error that will be bubbled up to the caller of
	// PublishPartial. Returning an error does not prevent other PublishActions
	// from executing or affect the PeerState map.
	Err error
}

type PublishActionsFn

type PublishActionsFn[PeerState any] func(peerStates map[peer.ID]PeerState, peerRequestsPartial func(peer.ID) bool) iter.Seq2[peer.ID, PublishAction]

PublishActionsFn should return an iterator of PublishActions describing what messages to send to whom.

The function SHOULD update the peer's peerState in the map to track the parts we've sent to this peer, along with any other peer-specific application data.

The function should use the peerRequestsPartial to avoid encoding a partial message if the peer did not request one.

A peer's peerState will be the zero value (nil for Pointer types) if this is the first time interacting with this peer. Applications can still eagerly push data in this case by returning the appropriate PublishAction.

Implementations SHOULD avoid returning duplicate or redundant EncodedPartsMetadata i.e. if a previously sent PartsMetadata is up to date, implementations SHOULD return `nil` for `EncodedPartsMetadata`.

type Router

type Router interface {
	SendRPC(p peer.ID, r *pb.PartialMessagesExtension, urgent bool)
	MeshPeers(topic string) iter.Seq[peer.ID]
	PeerRequestsPartial(peer peer.ID, topic string) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL