tangle

package
v0.2.4-0...-2c2ceb1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// MessageVersion defines the version of the message structure.
	MessageVersion uint8 = 1

	// MaxMessageSize defines the maximum size of a message.
	MaxMessageSize = 64 * 1024

	// MessageIDLength defines the length of an MessageID.
	MessageIDLength = 32

	// StrongParent identifies a strong parent in the bitmask.
	StrongParent uint8 = 1

	// WeakParent identifies a weak parent in the bitmask.
	WeakParent uint8 = 0

	// MinParentsCount defines the minimum number of parents a message must have.
	MinParentsCount = 1
	// MaxParentsCount defines the maximum number of parents a message must have.
	MaxParentsCount = 8
	// MinStrongParentsCount defines the minimum number of strong parents a message must have.
	MinStrongParentsCount = 1
)
View Source
const (
	// PrefixMessage defines the storage prefix for message.
	PrefixMessage byte = iota
	// PrefixMessageMetadata defines the storage prefix for message metadata.
	PrefixMessageMetadata
	// PrefixApprovers defines the storage prefix for approvers.
	PrefixApprovers
	// PrefixMissingMessage defines the storage prefix for missing message.
	PrefixMissingMessage

	// DBSequenceNumber defines the db sequence number.
	DBSequenceNumber = "seq"
)
View Source
const (
	// DefaultRetryInterval defines the Default Retry Interval of the message requester.
	DefaultRetryInterval = 10 * time.Second
)

Variables

View Source
var (
	// ErrInvalidPOWDifficultly is returned when the nonce of a message does not fulfill the PoW difficulty.
	ErrInvalidPOWDifficultly = errors.New("invalid PoW")

	// ErrMessageTooSmall is returned when the message does not contain enough data for the PoW.
	ErrMessageTooSmall = errors.New("message too small")

	// ErrInvalidSignature is returned when a message contains an invalid signature.
	ErrInvalidSignature = fmt.Errorf("invalid signature")

	// ErrReceivedDuplicateBytes is returned when duplicated bytes are rejected.
	ErrReceivedDuplicateBytes = fmt.Errorf("received duplicate bytes")
)
View Source
var EmptyMessageID = MessageID{}

EmptyMessageID is an empty id.

View Source
var (
	// ZeroWorker is a PoW worker that always returns 0 as the nonce.
	ZeroWorker = WorkerFunc(func([]byte) (uint64, error) { return 0, nil })
)

Functions

func ApproverFromObjectStorage

func ApproverFromObjectStorage(key []byte, _ []byte) (result objectstorage.StorableObject, err error)

ApproverFromObjectStorage is the factory method for Approvers stored in the ObjectStorage.

func MessageFromObjectStorage

func MessageFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

MessageFromObjectStorage restores a Message from the ObjectStorage.

func MessageMetadataFromObjectStorage

func MessageMetadataFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

MessageMetadataFromObjectStorage restores a MessageMetadata object from the ObjectStorage.

func MissingMessageFromObjectStorage

func MissingMessageFromObjectStorage(key []byte, data []byte) (result objectstorage.StorableObject, err error)

MissingMessageFromObjectStorage restores a MissingMessage from the ObjectStorage.

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) (result *Approver, consumedBytes int, err error)

ApproverFromBytes parses the given bytes into an approver.

func ApproverFromMarshalUtil

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

ApproverFromMarshalUtil parses a new approver from the given marshal util.

func NewApprover

func NewApprover(referencedMessageID MessageID, approverMessageID MessageID) *Approver

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

func (*Approver) ApproverMessageID

func (a *Approver) ApproverMessageID() MessageID

ApproverMessageID returns the ID of the message which referenced the given approved message.

func (*Approver) Bytes

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

Bytes returns the bytes of the approver.

func (*Approver) ObjectStorageKey

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

ObjectStorageKey marshals the keys of the stored approver into a byte array. This includes the referencedMessageID and the approverMessageID.

func (*Approver) ObjectStorageValue

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

ObjectStorageValue returns the value of the stored approver object.

func (*Approver) ReferencedMessageID

func (a *Approver) ReferencedMessageID() MessageID

ReferencedMessageID returns the ID of the message which is referenced by the approver.

func (*Approver) String

func (a *Approver) String() string

String returns the string representation of the approver.

func (*Approver) Update

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

Update updates the approver. This should should never happen and will panic if attempted.

type BytesFilter

type BytesFilter interface {
	// Filter filters up on the given bytes and peer and calls the acceptance callback
	// if the input passes or the rejection callback if the input is rejected.
	Filter(bytes []byte, peer *peer.Peer)
	// OnAccept registers the given callback as the acceptance function of the filter.
	OnAccept(callback func(bytes []byte, peer *peer.Peer))
	// OnReject registers the given callback as the rejection function of the filter.
	OnReject(callback func(bytes []byte, err error, peer *peer.Peer))
}

BytesFilter filters based on byte slices and peers.

type BytesRejectedEvent

type BytesRejectedEvent struct {
	Bytes []byte
	Peer  *peer.Peer
}

BytesRejectedEvent represents the parameters of bytesRejectedEvent

type CachedApprover

type CachedApprover struct {
	objectstorage.CachedObject
}

CachedApprover is a wrapper for a stored cached object representing an approver.

func (*CachedApprover) Consume

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

Consume consumes the cachedApprover. It releases the object when the callback is done. It returns true if the callback was called.

func (*CachedApprover) Unwrap

func (c *CachedApprover) Unwrap() *Approver

Unwrap unwraps the cached approver into the underlying approver. If stored object cannot be cast into an approver or has been deleted, it returns nil.

type CachedApprovers

type CachedApprovers []*CachedApprover

CachedApprovers defines a slice of *CachedApprover.

func (CachedApprovers) Consume

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

Consume calls *CachedApprover.Consume on element in the list.

type CachedMessage

type CachedMessage struct {
	objectstorage.CachedObject
}

CachedMessage defines a cached message. A wrapper for a cached object.

func (*CachedMessage) Consume

func (c *CachedMessage) Consume(consumer func(msg *Message)) bool

Consume consumes the cached object and releases it when the callback is done. It returns true if the callback was called.

func (*CachedMessage) Retain

func (c *CachedMessage) Retain() *CachedMessage

Retain registers a new consumer for the cached message.

func (*CachedMessage) Unwrap

func (c *CachedMessage) Unwrap() *Message

Unwrap returns the message wrapped by the cached message. If the wrapped object cannot be cast to a Message or has been deleted, it returns nil.

type CachedMessageEvent

type CachedMessageEvent struct {
	Message         *CachedMessage
	MessageMetadata *CachedMessageMetadata
}

CachedMessageEvent represents the parameters of cachedMessageEvent

type CachedMessageMetadata

type CachedMessageMetadata struct {
	objectstorage.CachedObject
}

CachedMessageMetadata is a wrapper for stored cached object that represents a message metadata.

func (*CachedMessageMetadata) Retain

Retain registers a new consumer for the cached message metadata.

func (*CachedMessageMetadata) Unwrap

Unwrap returns the underlying stored message metadata wrapped by the CachedMessageMetadata. If the stored object cannot be cast to MessageMetadata or is deleted, it returns nil.

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 Message

type Message struct {
	// base functionality of StorableObject
	objectstorage.StorableObjectFlags
	// contains filtered or unexported fields
}

Message represents the core message for the base layer Tangle.

func MessageFromBytes

func MessageFromBytes(bytes []byte) (result *Message, consumedBytes int, err error)

MessageFromBytes parses the given bytes into a message.

func MessageFromMarshalUtil

func MessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *Message, err error)

MessageFromMarshalUtil parses a message from the given marshal util.

func NewMessage

func NewMessage(strongParents []MessageID, weakParents []MessageID, issuingTime time.Time, issuerPublicKey ed25519.PublicKey, sequenceNumber uint64, payload payload.Payload, nonce uint64, signature ed25519.Signature) (result *Message)

NewMessage creates a new message with the details provided by the issuer.

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes returns the message in serialized byte form.

func (*Message) ForEachParent

func (m *Message) ForEachParent(consumer func(parent Parent))

ForEachParent executes a consumer func for each parent.

func (*Message) ForEachStrongParent

func (m *Message) ForEachStrongParent(consumer func(parent MessageID))

ForEachStrongParent executes a consumer func for each strong parent.

func (*Message) ForEachWeakParent

func (m *Message) ForEachWeakParent(consumer func(parent MessageID))

ForEachWeakParent executes a consumer func for each weak parent.

func (*Message) ID

func (m *Message) ID() (result MessageID)

ID returns the id of the message which is made up of the content id and parent1/parent2 ids. This id can be used for merkle proofs.

func (*Message) IssuerPublicKey

func (m *Message) IssuerPublicKey() ed25519.PublicKey

IssuerPublicKey returns the public key of the message issuer.

func (*Message) IssuingTime

func (m *Message) IssuingTime() time.Time

IssuingTime returns the time when this message was created.

func (*Message) Nonce

func (m *Message) Nonce() uint64

Nonce returns the nonce of the message.

func (*Message) ObjectStorageKey

func (m *Message) ObjectStorageKey() []byte

ObjectStorageKey returns the key of the stored message object. This returns the bytes of the message ID.

func (*Message) ObjectStorageValue

func (m *Message) ObjectStorageValue() []byte

ObjectStorageValue returns the value stored in object storage. This returns the bytes of message.

func (*Message) ParentsCount

func (m *Message) ParentsCount() uint8

ParentsCount returns the total parents count of this message.

func (*Message) Payload

func (m *Message) Payload() payload.Payload

Payload returns the payload of the message.

func (*Message) SequenceNumber

func (m *Message) SequenceNumber() uint64

SequenceNumber returns the sequence number of this message.

func (*Message) Signature

func (m *Message) Signature() ed25519.Signature

Signature returns the signature of the message.

func (*Message) String

func (m *Message) String() string

func (*Message) StrongParents

func (m *Message) StrongParents() MessageIDs

StrongParents returns a slice of all strong parents of the message.

func (*Message) Update

Update updates the object with the values of another object. Since a Message is immutable, this function is not implemented and panics.

func (*Message) VerifySignature

func (m *Message) VerifySignature() bool

VerifySignature verifies the signature of the message.

func (*Message) Version

func (m *Message) Version() uint8

Version returns the message version.

func (*Message) WeakParents

func (m *Message) WeakParents() MessageIDs

WeakParents returns a slice of all weak parents of the message.

type MessageExistsFunc

type MessageExistsFunc func(messageId MessageID) bool

MessageExistsFunc is a function that tells if a message exists.

type MessageFactory

type MessageFactory struct {
	Events *MessageFactoryEvents
	// contains filtered or unexported fields
}

MessageFactory acts as a factory to create new messages.

func NewMessageFactory

func NewMessageFactory(store kvstore.KVStore, sequenceKey []byte, localIdentity *identity.LocalIdentity, selector TipSelector) *MessageFactory

NewMessageFactory creates a new message factory.

func (*MessageFactory) IssuePayload

func (f *MessageFactory) IssuePayload(p payload.Payload) (*Message, error)

IssuePayload creates a new message including sequence number and tip selection and returns it. It also triggers the MessageConstructed event once it's done, which is for example used by the plugins to listen for messages that shall be attached to the tangle.

func (*MessageFactory) SetWorker

func (f *MessageFactory) SetWorker(worker Worker)

SetWorker sets the PoW worker to be used for the messages.

func (*MessageFactory) Shutdown

func (f *MessageFactory) Shutdown()

Shutdown closes the MessageFactory and persists the sequence number.

type MessageFactoryEvents

type MessageFactoryEvents struct {
	// Fired when a message is built including tips, sequence number and other metadata.
	MessageConstructed *events.Event
	// Fired when an error occurred.
	Error *events.Event
}

MessageFactoryEvents represents events happening on a message factory.

type MessageFilter

type MessageFilter interface {
	// Filter filters up on the given message and peer and calls the acceptance callback
	// if the input passes or the rejection callback if the input is rejected.
	Filter(msg *Message, peer *peer.Peer)
	// OnAccept registers the given callback as the acceptance function of the filter.
	OnAccept(callback func(msg *Message, peer *peer.Peer))
	// OnAccept registers the given callback as the rejection function of the filter.
	OnReject(callback func(msg *Message, err error, peer *peer.Peer))
}

MessageFilter filters based on messages and peers.

type MessageID

type MessageID [MessageIDLength]byte

MessageID identifies a message via its BLAKE2b-256 hash of its bytes.

func MessageIDFromBytes

func MessageIDFromBytes(bytes []byte) (result MessageID, consumedBytes int, err error)

MessageIDFromBytes unmarshals a message id from a sequence of bytes.

func MessageIDFromMarshalUtil

func MessageIDFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (MessageID, error)

MessageIDFromMarshalUtil is a wrapper for simplified unmarshaling in a byte stream using the marshalUtil package.

func NewMessageID

func NewMessageID(base58EncodedString string) (result MessageID, err error)

NewMessageID creates a new message id.

func (MessageID) Bytes

func (id MessageID) Bytes() []byte

Bytes returns the bytes of the MessageID.

func (*MessageID) MarshalBinary

func (id *MessageID) MarshalBinary() (result []byte, err error)

MarshalBinary marshals the MessageID into bytes.

func (MessageID) String

func (id MessageID) String() string

String returns the base58 encode of the MessageID.

func (*MessageID) UnmarshalBinary

func (id *MessageID) UnmarshalBinary(data []byte) (err error)

UnmarshalBinary unmarshals the bytes into an MessageID.

type MessageIDs

type MessageIDs []MessageID

MessageIDs is a slice of MessageID.

func (MessageIDs) ToStrings

func (ids MessageIDs) ToStrings() []string

ToStrings converts a slice of MessageIDs to a slice of strings.

type MessageMetadata

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

MessageMetadata defines the metadata for a message.

func MessageMetadataFromBytes

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

MessageMetadataFromBytes unmarshals the given bytes into a MessageMetadata.

func MessageMetadataFromMarshalUtil

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

MessageMetadataFromMarshalUtil parses a Message from the given MarshalUtil.

func NewMessageMetadata

func NewMessageMetadata(messageID MessageID) *MessageMetadata

NewMessageMetadata creates a new MessageMetadata from the specified messageID.

func (*MessageMetadata) Bytes

func (m *MessageMetadata) Bytes() []byte

Bytes returns a marshaled version of the whole MessageMetadata object.

func (*MessageMetadata) IsSolid

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

IsSolid returns true if the message represented by this metadata is solid. False otherwise.

func (*MessageMetadata) ObjectStorageKey

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

ObjectStorageKey returns the key of the stored message metadata object. This returns the bytes of the messageID.

func (*MessageMetadata) ObjectStorageValue

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

ObjectStorageValue returns the value of the stored message metadata object. This includes the receivedTime, solidificationTime and solid status.

func (*MessageMetadata) ReceivedTime

func (m *MessageMetadata) ReceivedTime() time.Time

ReceivedTime returns the time when the message was received.

func (*MessageMetadata) SetSolid

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

SetSolid sets the message associated with this metadata as solid. It returns true if the solid status is modified. False otherwise.

func (*MessageMetadata) SolidificationTime

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

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

func (*MessageMetadata) Update

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

Update updates the message metadata. This should never happen and will panic if attempted.

type MessageParsedEvent

type MessageParsedEvent struct {
	Message *Message
	Peer    *peer.Peer
}

MessageParsedEvent represents the parameters of messageParsedEvent

type MessageParser

type MessageParser struct {
	Events *MessageParserEvents
	// contains filtered or unexported fields
}

MessageParser parses messages and bytes and emits corresponding events for parsed and rejected messages.

func NewMessageParser

func NewMessageParser() (result *MessageParser)

NewMessageParser creates a new message parser.

func (*MessageParser) AddBytesFilter

func (p *MessageParser) AddBytesFilter(filter BytesFilter)

AddBytesFilter adds the given bytes filter to the parser.

func (*MessageParser) AddMessageFilter

func (p *MessageParser) AddMessageFilter(filter MessageFilter)

AddMessageFilter adds a new message filter to the parser.

func (*MessageParser) Parse

func (p *MessageParser) Parse(messageBytes []byte, peer *peer.Peer)

Parse parses the given message bytes.

type MessageParserEvents

type MessageParserEvents struct {
	// Fired when a message was parsed.
	MessageParsed *events.Event
	// Fired when submitted bytes are rejected by a filter.
	BytesRejected *events.Event
	// Fired when a message got rejected by a filter.
	MessageRejected *events.Event
}

MessageParserEvents represents events happening on a message parser.

type MessageRejectedEvent

type MessageRejectedEvent struct {
	Message *Message
	Peer    *peer.Peer
}

MessageRejectedEvent represents the parameters of messageRejectedEvent

type MessageRequester

type MessageRequester struct {
	Events *MessageRequesterEvents
	// contains filtered or unexported fields
}

MessageRequester takes care of requesting messages.

func NewMessageRequester

func NewMessageRequester(missingMessages []MessageID, optionalOptions ...Option) *MessageRequester

NewMessageRequester creates a new message requester.

func (*MessageRequester) RequestQueueSize

func (r *MessageRequester) RequestQueueSize() int

RequestQueueSize returns the number of scheduled message requests.

func (*MessageRequester) StartRequest

func (r *MessageRequester) StartRequest(id MessageID)

StartRequest initiates a regular triggering of the StartRequest event until it has been stopped using StopRequest.

func (*MessageRequester) StopRequest

func (r *MessageRequester) StopRequest(id MessageID)

StopRequest stops requests for the given message to further happen.

type MessageRequesterEvents

type MessageRequesterEvents struct {
	// Fired when a request for a given message should be sent.
	SendRequest *events.Event
	// MissingMessageAppeared is triggered when a message is actually present in the node's db although it was still being requested.
	MissingMessageAppeared *events.Event
}

MessageRequesterEvents represents events happening on a message requester.

type MessageSignatureFilter

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

MessageSignatureFilter filters messages based on whether their signatures are valid.

func NewMessageSignatureFilter

func NewMessageSignatureFilter() *MessageSignatureFilter

NewMessageSignatureFilter creates a new message signature filter.

func (*MessageSignatureFilter) Filter

func (f *MessageSignatureFilter) Filter(msg *Message, peer *peer.Peer)

Filter filters up on the given bytes and peer and calls the acceptance callback if the input passes or the rejection callback if the input is rejected.

func (*MessageSignatureFilter) OnAccept

func (f *MessageSignatureFilter) OnAccept(callback func(msg *Message, peer *peer.Peer))

OnAccept registers the given callback as the acceptance function of the filter.

func (*MessageSignatureFilter) OnReject

func (f *MessageSignatureFilter) OnReject(callback func(msg *Message, err error, peer *peer.Peer))

OnReject registers the given callback as the rejection function of the filter.

type MessageTipSelector

type MessageTipSelector struct {
	Events *MessageTipSelectorEvents
	// contains filtered or unexported fields
}

MessageTipSelector manages a map of tips and emits events for their removal and addition.

func NewMessageTipSelector

func NewMessageTipSelector(tips ...MessageID) *MessageTipSelector

NewMessageTipSelector creates a new tip-selector.

func (*MessageTipSelector) AddTip

func (t *MessageTipSelector) AddTip(msg *Message)

AddTip adds the given message as a tip.

func (*MessageTipSelector) Set

func (t *MessageTipSelector) Set(tips ...MessageID)

Set adds the given messageIDs as tips.

func (*MessageTipSelector) TipCount

func (t *MessageTipSelector) TipCount() int

TipCount the amount of current tips.

func (*MessageTipSelector) Tips

func (t *MessageTipSelector) Tips(count int) (parents []MessageID)

Tips returns count number of tips, maximum MaxParentsCount.

type MessageTipSelectorEvents

type MessageTipSelectorEvents struct {
	// Fired when a tip is added.
	TipAdded *events.Event
	// Fired when a tip is removed.
	TipRemoved *events.Event
}

MessageTipSelectorEvents represents event happening on the tip-selector.

type MissingMessage

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

MissingMessage represents a missing message.

func MissingMessageFromBytes

func MissingMessageFromBytes(bytes []byte) (result *MissingMessage, consumedBytes int, err error)

MissingMessageFromBytes parses the given bytes into a MissingMessage.

func MissingMessageFromMarshalUtil

func MissingMessageFromMarshalUtil(marshalUtil *marshalutil.MarshalUtil) (result *MissingMessage, err error)

MissingMessageFromMarshalUtil parses a MissingMessage from the given MarshalUtil.

func NewMissingMessage

func NewMissingMessage(messageID MessageID) *MissingMessage

NewMissingMessage creates new missing message with the specified messageID.

func (*MissingMessage) Bytes

func (m *MissingMessage) Bytes() []byte

Bytes returns a marshaled version of this MissingMessage.

func (*MissingMessage) MessageID

func (m *MissingMessage) MessageID() MessageID

MessageID returns the id of the message.

func (*MissingMessage) MissingSince

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

MissingSince returns the time since when this message is missing.

func (*MissingMessage) ObjectStorageKey

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

ObjectStorageKey returns the key of the stored missing message. This returns the bytes of the messageID of the missing message.

func (*MissingMessage) ObjectStorageValue

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

ObjectStorageValue returns the value of the stored missing message.

func (*MissingMessage) Update

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

Update update the missing message. It should never happen and will panic if called.

type MissingMessageAppearedEvent

type MissingMessageAppearedEvent struct {
	ID MessageID
}

MissingMessageAppearedEvent represents the parameters of missingMessageAppearedEvent

type Option

type Option func(*Options)

Option is a function which inits an option.

func RetryInterval

func RetryInterval(interval time.Duration) Option

RetryInterval creates an option which sets the retry interval to the given value.

type Options

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

Options holds options for a message requester.

type Parent

type Parent struct {
	ID   MessageID
	Type uint8
}

Parent is a parent that can be either strong or weak.

type PowFilter

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

PowFilter is a message bytes filter validating the PoW nonce.

func NewPowFilter

func NewPowFilter(worker *pow.Worker, difficulty int) *PowFilter

NewPowFilter creates a new PoW bytes filter.

func (*PowFilter) Filter

func (f *PowFilter) Filter(msgBytes []byte, p *peer.Peer)

Filter checks whether the given bytes pass the PoW validation and calls the corresponding callback.

func (*PowFilter) OnAccept

func (f *PowFilter) OnAccept(callback func([]byte, *peer.Peer))

OnAccept registers the given callback as the acceptance function of the filter.

func (*PowFilter) OnReject

func (f *PowFilter) OnReject(callback func([]byte, error, *peer.Peer))

OnReject registers the given callback as the rejection function of the filter.

type RecentlySeenBytesFilter

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

RecentlySeenBytesFilter filters so that bytes which were recently seen don't pass the filter.

func NewRecentlySeenBytesFilter

func NewRecentlySeenBytesFilter() *RecentlySeenBytesFilter

NewRecentlySeenBytesFilter creates a new recently seen bytes filter.

func (*RecentlySeenBytesFilter) Filter

func (f *RecentlySeenBytesFilter) Filter(bytes []byte, peer *peer.Peer)

Filter filters up on the given bytes and peer and calls the acceptance callback if the input passes or the rejection callback if the input is rejected.

func (*RecentlySeenBytesFilter) OnAccept

func (f *RecentlySeenBytesFilter) OnAccept(callback func(bytes []byte, peer *peer.Peer))

OnAccept registers the given callback as the acceptance function of the filter.

func (*RecentlySeenBytesFilter) OnReject

func (f *RecentlySeenBytesFilter) OnReject(callback func(bytes []byte, err error, peer *peer.Peer))

OnReject registers the given callback as the rejection function of the filter.

type SendRequestEvent

type SendRequestEvent struct {
	ID MessageID
}

SendRequestEvent represents the parameters of sendRequestEvent

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 (t *Tangle) Approvers(messageID MessageID) CachedApprovers

Approvers retrieves the approvers of a message from the tangle.

func (*Tangle) AttachMessage

func (t *Tangle) AttachMessage(msg *Message)

AttachMessage attaches a new message to the tangle.

func (*Tangle) DBStats

func (t *Tangle) DBStats() (solidCount int, messageCount int, avgSolidificationTime float64, missingMessageCount int)

DBStats returns the number of solid messages and total number of messages in the database (messageMetadataStorage, that should contain the messages as messageStorage), the number of messages in missingMessageStorage, furthermore the average time it takes to solidify messages.

func (*Tangle) DeleteMessage

func (t *Tangle) DeleteMessage(messageID MessageID)

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

func (*Tangle) DeleteMissingMessage

func (t *Tangle) DeleteMissingMessage(messageID MessageID)

DeleteMissingMessage deletes a message from the missingMessageStorage.

func (*Tangle) Message

func (t *Tangle) Message(messageID MessageID) *CachedMessage

Message retrieves a message from the tangle.

func (*Tangle) MessageMetadata

func (t *Tangle) MessageMetadata(messageID MessageID) *CachedMessageMetadata

MessageMetadata retrieves the metadata of a message from the tangle.

func (*Tangle) MissingMessages

func (t *Tangle) MissingMessages() (ids []MessageID)

MissingMessages return the ids of messages in missingMessageStorage

func (*Tangle) Prune

func (t *Tangle) Prune() error

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

func (*Tangle) RetrieveAllTips

func (t *Tangle) RetrieveAllTips() (tips []MessageID)

RetrieveAllTips returns the tips (i.e., solid messages that are not part of the approvers list). It iterates over the messageMetadataStorage, thus only use this method if necessary. TODO: improve this function.

func (*Tangle) Shutdown

func (t *Tangle) Shutdown() *Tangle

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

func (*Tangle) SolidifierWorkerPoolStatus

func (t *Tangle) SolidifierWorkerPoolStatus() (name string, load int)

SolidifierWorkerPoolStatus returns the name and the load of the workerpool.

func (*Tangle) StoreMessageWorkerPoolStatus

func (t *Tangle) StoreMessageWorkerPoolStatus() (name string, load int)

StoreMessageWorkerPoolStatus returns the name and the load of the workerpool.

type TipSelector

type TipSelector interface {
	Tips(count int) (parents []MessageID)
}

A TipSelector selects two tips, parent2 and parent1, for a new message to attach to.

type TipSelectorFunc

type TipSelectorFunc func(count int) (parents []MessageID)

The TipSelectorFunc type is an adapter to allow the use of ordinary functions as tip selectors.

func (TipSelectorFunc) Tips

func (f TipSelectorFunc) Tips(count int) (parents []MessageID)

Tips calls f().

type Worker

type Worker interface {
	DoPOW([]byte) (nonce uint64, err error)
}

A Worker performs the PoW for the provided message in serialized byte form.

type WorkerFunc

type WorkerFunc func([]byte) (uint64, error)

The WorkerFunc type is an adapter to allow the use of ordinary functions as a PoW performer.

func (WorkerFunc) DoPOW

func (f WorkerFunc) DoPOW(msg []byte) (uint64, error)

DoPOW calls f(msg).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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