pulse

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unknown           Number = 0
	MinPackagePrivate        = 1
	MaxPackagePrivate        = 255
	Reserved0         Number = 256

	LocalRelative Number = localRelative

	// MinTimePulse is the hardcoded first pulse number. Because first 65536 numbers are saved for the system's needs
	MinTimePulse = localRelative + 1
	MaxTimePulse = 1<<30 - 1

	// PulseNumberSize declares the number of bytes in the pulse number
	NumberSize = 4
)

========================================================= NB! To ADD a special pulse - see special_pulse_numbers.go =========================================================

View Source
const UnixTimeOfMaxTimePulse = UnixTimeOfMinTimePulse - MinTimePulse + MaxTimePulse // 2053-01-08 19:24:46 +0000 UTC
View Source
const UnixTimeOfMinTimePulse = 1546300800 // 2019-01-01 00:00:00 +0000 UTC

Variables

This section is empty.

Functions

func FlagsOf

func FlagsOf(n uint32) int

func IsValidAsPulseNumber

func IsValidAsPulseNumber(n int) bool

func SortData

func SortData(data []Data)

Types

type Data

type Data struct {
	PulseNumber Number
	DataExt
}

func NewExpectedPulsarData

func NewExpectedPulsarData(pn Number, deltaPrev uint16) Data

func NewFirstEphemeralData

func NewFirstEphemeralData() Data

func NewFirstPulsarData

func NewFirstPulsarData(delta uint16, entropy longbits.Bits256) Data

func NewPulsarData

func NewPulsarData(pn Number, deltaNext uint16, deltaPrev uint16, entropy longbits.Bits256) Data

func (Data) AsPulseData

func (r Data) AsPulseData() Data

func (Data) AsRange

func (r Data) AsRange() Range

func (Data) CreateNextEphemeralPulse

func (r Data) CreateNextEphemeralPulse() Data

func (Data) CreateNextExpected

func (r Data) CreateNextExpected() Data

func (Data) CreateNextPulsarPulse

func (r Data) CreateNextPulsarPulse(delta uint16, entropyGen EntropyFunc) Data

func (Data) CreateNextPulse

func (r Data) CreateNextPulse(entropyGen EntropyFunc) Data

func (Data) EnsureEphemeralData

func (r Data) EnsureEphemeralData()

func (Data) EnsurePulsarData

func (r Data) EnsurePulsarData()

func (Data) EnsurePulseData

func (r Data) EnsurePulseData()

func (Data) GetNextPulseDelta

func (r Data) GetNextPulseDelta() uint16

func (Data) GetNextPulseNumber

func (r Data) GetNextPulseNumber() (Number, bool)

func (Data) GetPrevPulseDelta

func (r Data) GetPrevPulseDelta() uint16

func (Data) GetPrevPulseNumber

func (r Data) GetPrevPulseNumber() (Number, bool)

func (Data) GetPulseEntropy

func (r Data) GetPulseEntropy() longbits.Bits256

func (Data) GetPulseNumber

func (r Data) GetPulseNumber() Number

func (Data) GetStartOfEpoch

func (r Data) GetStartOfEpoch() Number

func (Data) GetTimestamp

func (r Data) GetTimestamp() int64

func (Data) HasValidEpoch

func (r Data) HasValidEpoch() bool

func (Data) HasValidTimeEpoch

func (r Data) HasValidTimeEpoch() bool

func (Data) IsEmpty

func (r Data) IsEmpty() bool

func (Data) IsEmptyCompatibleWith

func (r Data) IsEmptyCompatibleWith(epoch Epoch) bool

func (Data) IsExpectedPulse

func (r Data) IsExpectedPulse() bool

func (Data) IsFirstPulse

func (r Data) IsFirstPulse() bool

func (Data) IsFromEphemeral

func (r Data) IsFromEphemeral() bool

func (Data) IsFromPulsar

func (r Data) IsFromPulsar() bool

func (Data) IsValidEphemeralData

func (r Data) IsValidEphemeralData() bool

func (Data) IsValidExpectedPulsarData

func (r Data) IsValidExpectedPulsarData() bool

func (Data) IsValidExpectedPulseData

func (r Data) IsValidExpectedPulseData() bool

func (Data) IsValidNext

func (r Data) IsValidNext(n Data) bool

func (Data) IsValidPrev

func (r Data) IsValidPrev(p Data) bool

func (Data) IsValidPulsarData

func (r Data) IsValidPulsarData() bool

func (Data) IsValidPulseData

func (r Data) IsValidPulseData() bool

func (Data) NextPulseNumber

func (r Data) NextPulseNumber() Number

func (Data) PrevPulseNumber

func (r Data) PrevPulseNumber() Number

func (Data) String

func (r Data) String() string

type DataExt

type DataExt struct {
	// ByteSize=44
	PulseEpoch     Epoch
	NextPulseDelta uint16
	PrevPulseDelta uint16
	// Unix millis when the pulse was generated by a Pulsar. MUST be zero otherwise.
	Timestamp    uint32
	PulseEntropy longbits.Bits256
}

type DataHolder

type DataHolder interface {
	GetPulseNumber() Number
	GetPulseData() Data
	GetPulseDataDigest() cryptkit.DigestHolder
}

type DataReader

type DataReader interface {
	GetPulseNumber() Number
	GetStartOfEpoch() Number
	GetPulseEntropy() longbits.Bits256
	GetNextPulseNumber() (Number, bool)
	GetPrevPulseNumber() (Number, bool)

	GetTimestamp() int64
	IsExpectedPulse() bool
	IsFromEphemeral() bool

	AsPulseData() Data
}

type DataSorter

type DataSorter struct {
	Data []Data
}

func (DataSorter) Len

func (d DataSorter) Len() int

func (DataSorter) Less

func (d DataSorter) Less(i, j int) bool

func (DataSorter) Swap

func (d DataSorter) Swap(i, j int)

type EntropyFunc

type EntropyFunc func() longbits.Bits256

type Epoch

type Epoch uint32

NB! Non-time epoch is ONLY allowed to be [1..255], range of [256..65535] is FORBIDDEN

const (
	InvalidPulseEpoch Epoch = iota

	// Epoch for pulses autogenerated by network during ephemeral network stage.
	EphemeralPulseEpoch

	// Epoch for missing pulses inside a range. Compatible with time pulses.
	ArticulationPulseEpoch

	MaxSpecialEpoch = iota - 1
)

func (Epoch) Classify

func (v Epoch) Classify() (isValid, isSpecial bool)

func (Epoch) IsArticulation

func (v Epoch) IsArticulation() bool

func (Epoch) IsCompatible

func (v Epoch) IsCompatible(vv Epoch) bool

func (Epoch) IsEphemeral

func (v Epoch) IsEphemeral() bool

func (Epoch) IsTimeEpoch

func (v Epoch) IsTimeEpoch() bool

func (Epoch) IsUnknown

func (v Epoch) IsUnknown() bool

func (Epoch) IsValidEpoch

func (v Epoch) IsValidEpoch() bool

type FindNumberFunc

type FindNumberFunc func(n Number, prevDelta, nextDelta uint16) bool

type Number

type Number uint32

Number is a type for pulse numbers.

Special values: 0 Unknown 1 .. 255 Reserved for package internal usage 256 Reserved 257 .. 65535 Reserved for platform wide usage 65536 Local relative pulse number 65537 .. 1<<30 - 1 Regular time based pulse numbers

NB! Range 0..256 IS RESERVED for internal operations There MUST BE NO references with PN < 256 ever visible to contracts / users.

const (

	// Jet is a special pulse number value that signifies jet ID.
	// TODO either JetPrefix or ShortJetId - both are viable for addressing
	// Local part (can be omitted) - then it is a reference to a specific record within the jet
	// or to a jet-local built-in contract (via Base part)
	Jet Number

	// BuiltinContract declares special pulse number that creates namespace for builtin contracts
	// Base part is type/contract identity, Local part (can be omitted) identifies a version
	BuiltinContract

	// Base part - see FullJetId, and it has an indication to represent a JetDrop reference.
	// Local part (can be omitted) - then it is a reference to a specific record within the jet
	JetGeneration // and JetDrop and JetContract

	// Node, it is identified by 224 bits of node's PK hash
	// Local part (can be omitted) - then it is a reference to a specific state of the node or
	// node-local built-in contracts
	Node

	// Reference to a part of lifeline's record that is reused within the same lifeline without copying.
	// Base part defines jet + position of a referenced content within the record
	// Local part is a record id within the relevant lifeline/jet
	RecordPayload

	// Identity of an external call - initially it is not bound to lifelines, hence the separate addressing.
	// Base part - same as of Node ref of the node accepted the call
	// Local part - pulse of seed, hash of request
	ExternalCall

	// Identity of an endpoint
	// Indicates when the endpoint is free-to-call, can be served by any node, or needs a special handling.
	EndpointAddress

	// Identity of data relevant to pulse, e.g. network state hash, network population, jet tree etc
	DataOfPulse
)

Number is a type for pulse numbers.

Special values:

  0 				Unknown
  1 .. 256			RESERVED. For package internal usage

257 .. 65279		Available for platform-wide usage

65280 .. 65535 RESERVED. For global maps and aliases 65536 Local relative pulse number 65537 .. 1<<30 - 1 Regular time based pulse numbers

NB! Range 0..256 IS RESERVED for internal operations There MUST BE NO references with PN < 256 ever visible to contracts / users.

func OfInt

func OfInt(n int) Number

func OfNow

func OfNow() Number

func OfTime

func OfTime(t time.Time) Number

func OfUint32

func OfUint32(n uint32) Number

func OfUnixTime

func OfUnixTime(u int64) Number

func (Number) AsApproximateTime

func (n Number) AsApproximateTime() (time.Time, error)

func (Number) AsEpoch

func (n Number) AsEpoch() Epoch

func (Number) AsUint32

func (n Number) AsUint32() uint32

func (Number) Bytes

func (n Number) Bytes() []byte

Bytes serializes pulse number. deprecated

func (Number) EnsureTimePulse

func (n Number) EnsureTimePulse() Number

func (Number) IsAfter

func (n Number) IsAfter(pn Number) bool

func (Number) IsBefore

func (n Number) IsBefore(pn Number) bool

func (Number) IsBeforeOrEq

func (n Number) IsBeforeOrEq(pn Number) bool

func (Number) IsEqOrAfter

func (n Number) IsEqOrAfter(pn Number) bool

func (Number) IsEqOrOut

func (n Number) IsEqOrOut(pn Number, prevDelta, nextDelta uint16) bool

func (Number) IsPackagePrivate

func (n Number) IsPackagePrivate() bool

func (Number) IsSpecial

func (n Number) IsSpecial() bool

func (Number) IsSpecialOrPrivate

func (n Number) IsSpecialOrPrivate() bool

func (Number) IsSpecialOrTimePulse

func (n Number) IsSpecialOrTimePulse() bool

func (Number) IsTimePulse

func (n Number) IsTimePulse() bool

func (Number) IsUnknown

func (n Number) IsUnknown() bool

func (Number) IsUnknownOrEqualTo

func (n Number) IsUnknownOrEqualTo(o Number) bool

func (Number) IsUnknownOrTimePulse

func (n Number) IsUnknownOrTimePulse() bool

func (Number) Next

func (n Number) Next(delta uint16) Number

func (Number) Prev

func (n Number) Prev(delta uint16) Number

func (Number) String

func (n Number) String() string

func (Number) TryNext

func (n Number) TryNext(delta uint16) (Number, bool)

func (Number) TryPrev

func (n Number) TryPrev(delta uint16) (Number, bool)

func (Number) WithFlags

func (n Number) WithFlags(flags int) uint32

type OnePulseRange

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

func NewOnePulseRange

func NewOnePulseRange(data Data) OnePulseRange

func (OnePulseRange) EnumData

func (p OnePulseRange) EnumData(fn func(Data) bool) bool

func (OnePulseRange) EnumNonArticulatedData

func (p OnePulseRange) EnumNonArticulatedData(fn func(Data) bool) bool

func (OnePulseRange) EnumNonArticulatedNumbers

func (p OnePulseRange) EnumNonArticulatedNumbers(fn FindNumberFunc) bool

func (OnePulseRange) EnumNumbers

func (p OnePulseRange) EnumNumbers(fn FindNumberFunc) bool

func (OnePulseRange) Equal

func (p OnePulseRange) Equal(o Range) bool

func (OnePulseRange) IsArticulated

func (p OnePulseRange) IsArticulated() bool

func (OnePulseRange) IsSingular

func (p OnePulseRange) IsSingular() bool

func (OnePulseRange) IsValidNext

func (p OnePulseRange) IsValidNext(a Range) bool

func (OnePulseRange) IsValidPrev

func (p OnePulseRange) IsValidPrev(a Range) bool

func (OnePulseRange) LeftBoundNumber

func (p OnePulseRange) LeftBoundNumber() Number

func (OnePulseRange) LeftPrevDelta

func (p OnePulseRange) LeftPrevDelta() uint16

func (OnePulseRange) RightBoundData

func (p OnePulseRange) RightBoundData() Data

type Range

type Range interface {
	// LeftBoundNumber provides a left bound of the range. It may be an expected pulse.
	LeftBoundNumber() Number
	// LeftPrevDelta is PrevDelta associated with the left boundary (refers to a pulse _before_ the left boundary).
	LeftPrevDelta() uint16

	// RightBoundData returns a right bound of the range. MUST be a valid or expected pulse data.
	RightBoundData() Data

	// IsArticulated indicates that this range requires articulated pulses to be properly chained.
	IsArticulated() bool
	// IsSingular indicates that this range is a singular and contains only one pulse.
	IsSingular() bool

	// EnumNumbers iterates from smaller to higher pulses, over both provided and articulated pulses within the range.
	EnumNumbers(fn FindNumberFunc) bool
	// EnumNonArticulatedNumbers iterates from smaller to higher pulses, only over the provided pulse data within the range.
	EnumNonArticulatedNumbers(fn FindNumberFunc) bool

	// EnumData iterates from smaller to higher pulses, over both provided and articulated pulse data within the range.
	EnumData(func(Data) bool) bool
	// EnumNonArticulatedData iterates from smaller to higher pulses, only over the provided pulse data within the range.
	EnumNonArticulatedData(func(Data) bool) bool

	// IsValidNext returns true then the given range is next immediate range
	IsValidNext(Range) bool
	// IsValidPrev returns true then the given range is prev immediate range
	IsValidPrev(Range) bool
	// Equal returns true when both ranges are equal
	Equal(Range) bool
}

func NewLeftGapRange

func NewLeftGapRange(left Number, leftPrevDelta uint16, right Data) Range

Creates a range that covers a gap between the last expected pulse and the last available one. Will panic when pulse are overlapping and can't be properly connected. Supports gaps with delta > 65535

func NewPulseRange

func NewPulseRange(data []Data) Range

Creates a range that consists of both connected and disconnected pulses. Sequence MUST be sorted, an expected pulse is allowed at [0] Will panic when pulse are overlapping and can't be properly connected. Supports gaps with delta > 65535

func NewSequenceRange

func NewSequenceRange(data []Data) Range

Creates a range that consists of >0 properly connected pulses. Sequence MUST be sorted, all pulses must be connected, otherwise use NewPulseRange() Will panic when pulse are overlapping and can't be properly connected. Supports gaps with delta > 65535

Jump to

Keyboard shortcuts

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