pending_store

package
v0.0.0-...-8cb8a38 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_CLEAR_EXPIRED_INTERVAL = time.Second * 30

Variables

View Source
var (
	ErrGroupNotFound = errors.New("message group not found")
)

Functions

This section is empty.

Types

type MessageWithPeerMetadata

type MessageWithPeerMetadata struct {
	BroadcastMessage types.BroadcastMessage

	// Not transmitted over wire, added when received.
	PeerID peer.ID

	Context context.Context
}

MessageWithPeerMetadata is a message with metadata about the peer that sent it.

type PeerMessageGroup

type PeerMessageGroup struct {
	Messages map[peer.ID]*MessageWithPeerMetadata
}

PeerMessageGroup is a group of the same message from different peers to be validated.

func NewPeerMessageGroup

func NewPeerMessageGroup() *PeerMessageGroup

NewPeerMessageGroup returns a new PeerMessageGroup

func (*PeerMessageGroup) Add

Add adds a message to the group, returning true if it replaced a message with the same peer ID.

func (*PeerMessageGroup) Completed

func (g *PeerMessageGroup) Completed(hostID peer.ID, recipients []peer.ID) bool

Completed returns true if the number of received messages matches the number of recipients.

func (*PeerMessageGroup) GetMessageData

func (g *PeerMessageGroup) GetMessageData() (types.BroadcastMessage, bool)

GetMessageData returns the underlying MessageData for the group. This should be called *after* Validate() has been called and confirmed to have no errors. This may return false if the group was created but did not receive any messages (ie. when broadcasting)

func (*PeerMessageGroup) Len

func (g *PeerMessageGroup) Len() int

Len returns the number of messages in the group.

func (*PeerMessageGroup) Validate

func (g *PeerMessageGroup) Validate() error

Validate returns true if all messages in the group are the same.

type PendingMessagesStore

type PendingMessagesStore struct {
	// contains filtered or unexported fields
}

PendingMessagesStore stores pending messages and removes expired messages.

func NewPendingMessagesStore

func NewPendingMessagesStore(expire_interval time.Duration) *PendingMessagesStore

NewPendingMessagesStore returns a new PendingMessagesStore and starts a background goroutine to remove expired message groups.

func (*PendingMessagesStore) AddMessage

AddMessage adds a message to it's corresponding pending message group, returning an error if it is invalid.

func (*PendingMessagesStore) ContainsGroup

func (pm *PendingMessagesStore) ContainsGroup(msgID string) bool

ContainsGroup returns true if the given message ID is in the store.

func (*PendingMessagesStore) DeleteGroup

func (pm *PendingMessagesStore) DeleteGroup(msgID string) error

DeleteGroup deletes the group with the given message ID.

func (*PendingMessagesStore) GroupIsCompleted

func (pm *PendingMessagesStore) GroupIsCompleted(
	msgID string,
	hostID peer.ID,
	recipients []peer.ID,
) (types.BroadcastMessage, bool)

GroupIsCompleted returns (the broadcast message and true) if the number of received messages matches the number of recipients.

func (*PendingMessagesStore) TryNewGroup

func (pm *PendingMessagesStore) TryNewGroup(msgID string) bool

TryNewGroup creates a new PeerMessageGroup for the given message ID and returns true if it was created. Returns false if the group already exists.

Jump to

Keyboard shortcuts

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