Documentation ¶
Index ¶
- Constants
- Variables
- type MessageWithPeerMetadata
- type PeerMessageGroup
- func (g *PeerMessageGroup) Add(msg *MessageWithPeerMetadata) error
- func (g *PeerMessageGroup) Completed(hostID peer.ID, recipients []peer.ID) bool
- func (g *PeerMessageGroup) GetMessageData() (types.BroadcastMessage, bool)
- func (g *PeerMessageGroup) Len() int
- func (g *PeerMessageGroup) Validate() error
- type PendingMessagesStore
- func (pm *PendingMessagesStore) AddMessage(msg MessageWithPeerMetadata) error
- func (pm *PendingMessagesStore) ContainsGroup(msgID string) bool
- func (pm *PendingMessagesStore) DeleteGroup(msgID string) error
- func (pm *PendingMessagesStore) GroupIsCompleted(msgID string, hostID peer.ID, recipients []peer.ID) (types.BroadcastMessage, bool)
- func (pm *PendingMessagesStore) TryNewGroup(msgID string) bool
Constants ¶
const DEFAULT_CLEAR_EXPIRED_INTERVAL = time.Second * 30
Variables ¶
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 ¶
func (g *PeerMessageGroup) Add(msg *MessageWithPeerMetadata) error
Add adds a message to the group, returning true if it replaced a message with the same peer ID.
func (*PeerMessageGroup) Completed ¶
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 ¶
func (pm *PendingMessagesStore) AddMessage(msg MessageWithPeerMetadata) error
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.