conversation

package
v4.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: BSD-2-Clause, BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageIdLen          = 32
	TruncatedMessageIdLen = 8
)

Constants for data length.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buff

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

Buff is a circular buffer which containing Message's.

func LoadBuff

func LoadBuff(kv versioned.KV) (*Buff, error)

LoadBuff loads the ring buffer from storage. It loads all messages from storage and repopulates the buffer.

func NewBuff

func NewBuff(kv versioned.KV, n int) (*Buff, error)

NewBuff initializes a new ring buffer with size n.

func (*Buff) Add

func (b *Buff) Add(id MessageID, timestamp time.Time) error

Add pushes a message to the circular buffer Buff.

func (*Buff) Get

func (b *Buff) Get() *Message

Get retrieves the most recent entry.

func (*Buff) GetByMessageID

func (b *Buff) GetByMessageID(id MessageID) (*Message, error)

GetByMessageID looks up and returns the message with MessageID ID from the lookup map. If the message does not exist, an error is returned.

func (*Buff) GetNextMessage

func (b *Buff) GetNextMessage(id MessageID) (*Message, error)

GetNextMessage looks up the Message with the next sequential MessageID in the ring buffer after the Message with the requested MessageID.

type Conversation

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

func LoadOrMakeConversation

func LoadOrMakeConversation(kv versioned.KV, partner *id.ID) *Conversation

LoadOrMakeConversation returns the Conversation with the given ID, if it can be found in KV. Otherwise, a new conversation with the given ID is generated, saved to KV, and returned.

func (*Conversation) GetNextSendID

func (c *Conversation) GetNextSendID() (uint64, uint32)

GetNextSendID returns the next sendID in both full and truncated formats.

func (*Conversation) ProcessReceivedMessageID

func (c *Conversation) ProcessReceivedMessageID(mid uint32) uint64

ProcessReceivedMessageID finds the full 64-bit message ID and updates the internal last message ID if the new ID is newer.

type Message

type Message struct {
	MessageId MessageID // The ID of the message
	Timestamp time.Time
	// contains filtered or unexported fields
}

Message is the structure held in a ring buffer. It represents a received message by the user, which needs its reception verified to the original sender of the message.

type MessageID

type MessageID [MessageIdLen]byte

MessageID is the ID of a message stored in a Message.

func NewMessageIdFromBytes

func NewMessageIdFromBytes(data []byte) MessageID

NewMessageIdFromBytes creates a MessageID from byte data.

func (MessageID) Bytes

func (mid MessageID) Bytes() []byte

Bytes returns the byte data of the MessageID.

func (MessageID) String

func (mid MessageID) String() string

String returns a base 64 encoding of the MessageID. This functions adheres to the fmt.Stringer interface.

type Store

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

func NewStore

func NewStore(kv versioned.KV) *Store

NewStore returns a new conversation Store made off of the KV.

func (*Store) Delete

func (s *Store) Delete(partner *id.ID)

Delete deletes the conversation with the given partner ID from memory and storage. Panics if the object cannot be deleted from storage.

func (*Store) Get

func (s *Store) Get(partner *id.ID) *Conversation

Get gets the conversation with the given partner ID from memory, if it is there. Otherwise, it loads it from disk.

Jump to

Keyboard shortcuts

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