tangle

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0, BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixMessage byte = iota
	PrefixMessageMetadata
	PrefixApprovers
	PrefixMissingMessage
)
View Source
const (
	// MaxMissingTimeBeforeCleanup is  the max. amount of time a message can be marked as missing
	// before it is ultimately un-marked as missing.
	MaxMissingTimeBeforeCleanup = 30 * time.Second
	// MissingCheckInterval is the interval on which it is checked whether a missing
	// message is still missing.
	MissingCheckInterval = 5 * time.Second
)

Variables

This section is empty.

Functions

func ApproverFromStorageKey

func ApproverFromStorageKey(key []byte, optionalTargetObject ...*Approver) (result objectstorage.StorableObject, consumedBytes int, err error)

ApproverFromStorageKey returns an approver for the given key.

func MessageMetadataFromStorageKey

func MessageMetadataFromStorageKey(key []byte) (result objectstorage.StorableObject, consumedBytes int, err error)

func MissingMessageFromStorageKey

func MissingMessageFromStorageKey(key []byte, optionalTargetObject ...*MissingMessage) (result objectstorage.StorableObject, consumedBytes int, err error)

Types

type Approver

type Approver struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Approver is an approver of a given referenced message.

func ApproverFromBytes

func ApproverFromBytes(bytes []byte, optionalTargetObject ...*Approver) (result *Approver, err error, consumedBytes int)

ApproverFromBytes parses the given bytes into an approver.

func NewApprover

func NewApprover(referencedMessageId message.Id, approverMessageId message.Id) *Approver

NewApprover creates a new approver relation to the given approved/referenced message.

func ParseApprover

func ParseApprover(marshalUtil *marshalutil.MarshalUtil, optionalTargetObject ...*Approver) (result *Approver, err error)

ParseApprover parses a new approver from the given marshal util.

func (*Approver) ApproverMessageId

func (approver *Approver) ApproverMessageId() message.Id

ApproverMessageId returns the id of the message which referenced the given approved message.

func (*Approver) Bytes

func (approver *Approver) Bytes() []byte

func (*Approver) ObjectStorageKey

func (approver *Approver) ObjectStorageKey() []byte

func (*Approver) ObjectStorageValue

func (approver *Approver) ObjectStorageValue() (result []byte)

func (*Approver) ReferencedMessageId

func (approver *Approver) ReferencedMessageId() message.Id

ReferencedMessageId returns the id of the message which is referenced by the approver.

func (*Approver) String

func (approver *Approver) String() string

func (*Approver) UnmarshalObjectStorageValue

func (approver *Approver) UnmarshalObjectStorageValue(data []byte) (consumedBytes int, err error)

func (*Approver) Update

func (approver *Approver) Update(other objectstorage.StorableObject)

type CachedApprover

type CachedApprover struct {
	objectstorage.CachedObject
}

func (*CachedApprover) Consume

func (cachedApprover *CachedApprover) Consume(consumer func(approver *Approver)) (consumed bool)

func (*CachedApprover) Unwrap

func (cachedApprover *CachedApprover) Unwrap() *Approver

type CachedApprovers

type CachedApprovers []*CachedApprover

func (CachedApprovers) Consume

func (cachedApprovers CachedApprovers) Consume(consumer func(approver *Approver)) (consumed bool)

type CachedMessageMetadata

type CachedMessageMetadata struct {
	objectstorage.CachedObject
}

func (*CachedMessageMetadata) Retain

func (cachedMessageMetadata *CachedMessageMetadata) Retain() *CachedMessageMetadata

func (*CachedMessageMetadata) Unwrap

func (cachedMessageMetadata *CachedMessageMetadata) Unwrap() *MessageMetadata

type Events

type Events struct {
	// Fired when a message has been attached.
	MessageAttached *events.Event
	// Fired when a message has been solid, i.e. its past cone
	// is known and in the database.
	MessageSolid *events.Event
	// Fired when a message which was previously marked as missing was received.
	MissingMessageReceived *events.Event
	// Fired when a message is missing which is needed to solidify a given approver message.
	MessageMissing *events.Event
	// Fired when a message was missing for too long and is
	// therefore considered to be unsolidifiable.
	MessageUnsolidifiable *events.Event
	// Fired when a message was removed from storage.
	MessageRemoved *events.Event
}

Events represents events happening on the base layer Tangle.

type MessageMetadata

type MessageMetadata struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

func MessageMetadataFromBytes

func MessageMetadataFromBytes(bytes []byte) (result *MessageMetadata, err error, consumedBytes int)

func NewMessageMetadata

func NewMessageMetadata(messageId message.Id) *MessageMetadata

func ParseMessageMetadata

func ParseMessageMetadata(marshalUtil *marshalutil.MarshalUtil) (result *MessageMetadata, err error)

func (*MessageMetadata) IsSolid

func (messageMetadata *MessageMetadata) IsSolid() (result bool)

func (*MessageMetadata) ObjectStorageKey

func (messageMetadata *MessageMetadata) ObjectStorageKey() []byte

func (*MessageMetadata) ObjectStorageValue

func (messageMetadata *MessageMetadata) ObjectStorageValue() []byte

func (*MessageMetadata) SetSolid

func (messageMetadata *MessageMetadata) SetSolid(solid bool) (modified bool)

func (*MessageMetadata) SolidificationTime

func (messageMetadata *MessageMetadata) SolidificationTime() time.Time

SolidificationTime returns the time when the message was marked to be solid.

func (*MessageMetadata) UnmarshalObjectStorageValue

func (messageMetadata *MessageMetadata) UnmarshalObjectStorageValue(data []byte) (consumedBytes int, err error)

func (*MessageMetadata) Update

func (messageMetadata *MessageMetadata) Update(other objectstorage.StorableObject)

type MissingMessage

type MissingMessage struct {
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

func NewMissingMessage

func NewMissingMessage(messageId message.Id) *MissingMessage

func (*MissingMessage) MessageId

func (missingMessage *MissingMessage) MessageId() message.Id

MessageId returns the id of the message.

func (*MissingMessage) MissingSince

func (missingMessage *MissingMessage) MissingSince() time.Time

MissingSince returns the time since when this message is missing.

func (*MissingMessage) ObjectStorageKey

func (missingMessage *MissingMessage) ObjectStorageKey() []byte

func (*MissingMessage) ObjectStorageValue

func (missingMessage *MissingMessage) ObjectStorageValue() (result []byte)

func (*MissingMessage) UnmarshalObjectStorageValue

func (missingMessage *MissingMessage) UnmarshalObjectStorageValue(data []byte) (consumedBytes int, err error)

func (*MissingMessage) Update

func (missingMessage *MissingMessage) Update(other objectstorage.StorableObject)

type Tangle

type Tangle struct {
	Events Events
	// contains filtered or unexported fields
}

Tangle represents the base layer of messages.

func New

func New(store kvstore.KVStore) (result *Tangle)

New creates a new Tangle.

func (*Tangle) Approvers

func (tangle *Tangle) Approvers(messageId message.Id) CachedApprovers

Approvers retrieves the approvers of a message from the tangle.

func (*Tangle) AttachMessage

func (tangle *Tangle) AttachMessage(msg *message.Message)

AttachMessage attaches a new message to the tangle.

func (*Tangle) DeleteMessage

func (tangle *Tangle) DeleteMessage(messageId message.Id)

DeleteMessage deletes a message and its association to approvees by un-marking the given message as an approver.

func (*Tangle) Message

func (tangle *Tangle) Message(messageId message.Id) *message.CachedMessage

Message retrieves a message from the tangle.

func (*Tangle) MessageMetadata

func (tangle *Tangle) MessageMetadata(messageId message.Id) *CachedMessageMetadata

MessageMetadata retrieves the metadata of a message from the tangle.

func (*Tangle) MonitorMissingMessages

func (tangle *Tangle) MonitorMissingMessages(shutdownSignal <-chan struct{})

MonitorMissingMessages continuously monitors for missing messages and eventually deletes them if they don't become available in a certain time frame.

func (*Tangle) Prune

func (tangle *Tangle) Prune() error

Prune resets the database and deletes all objects (good for testing or "node resets").

func (*Tangle) Shutdown

func (tangle *Tangle) Shutdown() *Tangle

Shutdown marks the tangle as stopped, so it will not accept any new messages (waits for all backgroundTasks to finish).

Jump to

Keyboard shortcuts

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