core

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package core contains common definitions used by other modules.

Index

Constants

View Source
const (
	// Joined
	NodeJoined = NodeState(iota + 1)
	// Prepared
	NodePrepared
	// Active
	NodeActive
	// Leaved
	NodeLeaved
	// Suspended
	NodeSuspended
)

TODO: document all node states

View Source
const (
	// RoleVirtualExecutor is responsible for current pulse CPU operations.
	RoleVirtualExecutor = JetRole(iota + 1)
	// RoleVirtualValidator is responsible for previous pulse CPU operations.
	RoleVirtualValidator
	// RoleLightExecutor is responsible for current pulse Disk operations.
	RoleLightExecutor
	// RoleLightValidator is responsible for previous pulse Disk operations.
	RoleLightValidator
	// RoleHeavyExecutor is responsible for permanent Disk operations.
	RoleHeavyExecutor
)
View Source
const (
	PulseNumberSize = 4
	EntropySize     = 64
)
View Source
const (
	// RecordHashSize is a record hash size. We use 224-bit SHA-3 hash (28 bytes).
	RecordHashSize = 28
	// RecordIDSize is relative record address.
	RecordIDSize = PulseNumberSize + RecordHashSize
	// RecordRefSize is absolute records address (including domain ID).
	RecordRefSize = RecordIDSize * 2
)
View Source
const FirstPulseDate = 1535760000 //09/01/2018 @ 12:00am (UTC)

Hardcoded date of first pulse

View Source
const FirstPulseNumber = 65536

Variables

This section is empty.

Functions

func CalculateMsToNextPulse added in v0.4.0

func CalculateMsToNextPulse(previousPulse PulseNumber, now time.Time) time.Duration

Types

type ActiveNode added in v0.4.0

type ActiveNode struct {
	// NodeID is the unique identifier of the node
	NodeID RecordRef
	// PulseNum is the pulse number after which the new state is assigned to the node
	PulseNum PulseNumber
	// State is the node state
	State NodeState
	// JetRoles is the set of candidate JetRoles for the node
	JetRoles JetRoleMask
	// PublicKey is the public key of the node
	PublicKey []byte
}

type Arguments

type Arguments []byte

Arguments is a dedicated type for arguments, that represented as bynary cbored blob

type ArtifactManager

type ArtifactManager interface {
	// RootRef returns the root record reference.
	//
	// Root record is the parent for all top-level records.
	RootRef() *RecordRef

	// GetCode returns code from code record by provided reference according to provided machine preference.
	//
	// This method is used by VM to fetch code for execution.
	GetCode(ref RecordRef, machinePref []MachineType) (CodeDescriptor, error)

	// GetClass returns descriptor for provided state.
	//
	// If provided state is nil, the latest state will be returned (with deactivation check). Returned descriptor will
	// provide methods for fetching all related data.
	GetClass(head RecordRef, state *RecordRef) (ClassDescriptor, error)

	// GetObject returns descriptor for provided state.
	//
	// If provided state is nil, the latest state will be returned (with deactivation check). Returned descriptor will
	// provide methods for fetching all related data.
	GetObject(head RecordRef, state *RecordRef) (ObjectDescriptor, error)

	// GetDelegate returns provided object's delegate reference for provided class.
	//
	// Object delegate should be previously created for this object. If object delegate does not exist, an error will
	// be returned.
	GetDelegate(head, asClass RecordRef) (*RecordRef, error)

	// DeclareType creates new type record in storage.
	//
	// Type is a contract interface. It contains one method signature.
	DeclareType(domain, request RecordRef, typeDec []byte) (*RecordRef, error)

	// DeployCode creates new code record in storage.
	//
	// Code records are used to activate class or as migration code for an object.
	DeployCode(domain, request RecordRef, codeMap map[MachineType][]byte) (*RecordRef, error)

	// ActivateClass creates activate class record in storage. Provided code reference will be used as a class code.
	//
	// Activation reference will be this class'es identifier and referred as "class head".
	ActivateClass(domain, request RecordRef) (*RecordRef, error)

	// DeactivateClass creates deactivate record in storage. Provided reference should be a reference to the head of
	// the class. If class is already deactivated, an error should be returned.
	//
	// Deactivated class cannot be changed or instantiate objects.
	DeactivateClass(domain, request, class RecordRef) (*RecordRef, error)

	// UpdateClass creates amend class record in storage. Provided reference should be a reference to the head of
	// the class. Migrations are references to code records.
	//
	// Returned reference will be the latest class state (exact) reference. Migration code will be executed by VM to
	// migrate objects memory in the order they appear in provided slice.
	UpdateClass(domain, request, class, code RecordRef, migrationRefs []RecordRef) (*RecordRef, error)

	// ActivateObject creates activate object record in storage. Provided class reference will be used as object's class.
	// If memory is not provided, the class default memory will be used.
	//
	// Activation reference will be this object's identifier and referred as "object head".
	ActivateObject(domain, request, class, parent RecordRef, memory []byte) (*RecordRef, error)

	// ActivateObjectDelegate is similar to ActivateObj but it created object will be parent's delegate of provided class.
	ActivateObjectDelegate(domain, request, class, parent RecordRef, memory []byte) (*RecordRef, error)

	// DeactivateObject creates deactivate object record in storage. Provided reference should be a reference to the head
	// of the object. If object is already deactivated, an error should be returned.
	//
	// Deactivated object cannot be changed.
	DeactivateObject(domain, request, obj RecordRef) (*RecordRef, error)

	// UpdateObject creates amend object record in storage. Provided reference should be a reference to the head of the
	// object. Provided memory well be the new object memory.
	//
	// Returned reference will be the latest object state (exact) reference.
	UpdateObject(domain, request, obj RecordRef, memory []byte) (*RecordRef, error)
}

ArtifactManager is a high level storage interface.

type Bootstrapper added in v0.2.0

type Bootstrapper interface {
	GetRootDomainRef() *RecordRef
}

Bootstrapper is the global bootstrapper handler. Other system parts communicate with bootstrapper through it.

type Cascade added in v0.2.0

type Cascade struct {
	// NodeIds contains the slice of node identifiers that will receive the message
	NodeIds []RecordRef
	// GeneratedEntropy is used for pseudorandom cascade building
	Entropy Entropy
	// Replication factor is the number of children nodes of the each node of the cascade
	ReplicationFactor uint
}

Cascade contains routing data for cascade sending

type ClassDescriptor

type ClassDescriptor interface {
	// HeadRef returns head reference to represented class record.
	HeadRef() *RecordRef

	// StateRef returns reference to represented class state record.
	StateRef() *RecordRef

	// CodeDescriptor returns descriptor for fetching class's code data.
	CodeDescriptor(machinePref []MachineType) (CodeDescriptor, error)
}

ClassDescriptor represents meta info required to fetch all object data.

type CodeDescriptor

type CodeDescriptor interface {
	// Ref returns reference to represented code record.
	Ref() *RecordRef

	// MachineType returns first available machine type for provided machine preference.
	MachineType() MachineType

	// Code returns code for first available machine type for provided machine preference.
	Code() []byte
}

CodeDescriptor represents meta info required to fetch all code data.

type Component

type Component interface {
	Start(components Components) error
	Stop() error
}

Component controller methods

type Components

type Components struct {
	Network      Network
	Ledger       Ledger
	LogicRunner  LogicRunner
	MessageBus   MessageBus
	Bootstrapper Bootstrapper
	APIRunner    Component
	Metrics      Component
}

Components is a registry for other core interfaces Fields order are important and represent start and stop order in the daemon

type Entropy added in v0.2.0

type Entropy [EntropySize]byte

Entropy is 64 random bytes used in every pseudo-random calculations.

type JetCoordinator added in v0.0.6

type JetCoordinator interface {
	// IsAuthorized checks for role on concrete pulse for the address.
	IsAuthorized(role JetRole, obj RecordRef, pulse PulseNumber, node RecordRef) (bool, error)

	// QueryRole returns node refs responsible for role bound operations for given object and pulse.
	QueryRole(role JetRole, obj RecordRef, pulse PulseNumber) ([]RecordRef, error)
}

JetCoordinator provides methods for calculating Jet affinity (e.g. to which Jet a message should be sent).

type JetRole added in v0.0.6

type JetRole int

JetRole is number representing a node role.

type JetRoleMask added in v0.4.0

type JetRoleMask uint64

JetRoleMask is bitmask for the set of candidate JetRoles

func (JetRoleMask) IsSet added in v0.4.0

func (mask JetRoleMask) IsSet(role JetRole) bool

func (*JetRoleMask) Set added in v0.4.0

func (mask *JetRoleMask) Set(role JetRole)

func (*JetRoleMask) Unset added in v0.4.0

func (mask *JetRoleMask) Unset(role JetRole)

type Ledger

type Ledger interface {
	// GetArtifactManager returns artifact manager to work with.
	GetArtifactManager() ArtifactManager

	// GetJetCoordinator returns jet coordinator to work with.
	GetJetCoordinator() JetCoordinator

	// GetPulseManager returns pulse manager to work with.
	GetPulseManager() PulseManager
}

Ledger is the global ledger handler. Other system parts communicate with ledger through it.

type Logger added in v0.0.6

type Logger interface {
	// SetLevel sets log level.
	SetLevel(string) error
	// GetLevel gets log level.
	GetLevel() string

	// Debug logs a message at level Debug.
	Debug(...interface{})
	// Debugln logs a message at level Debug.
	Debugln(...interface{})
	// Debugf formatted logs a message at level Debug.
	Debugf(string, ...interface{})

	// Info logs a message at level Info.
	Info(...interface{})
	// Infoln logs a message at level Info.
	Infoln(...interface{})
	// Infof formatted logs a message at level Info.
	Infof(string, ...interface{})

	// Warn logs a message at level Warn.
	Warn(...interface{})
	// Warnln logs a message at level Warn.
	Warnln(...interface{})
	// Warnf formatted logs a message at level Warn.
	Warnf(string, ...interface{})

	// Error logs a message at level Error.
	Error(...interface{})
	// Errorln logs a message at level Error.
	Errorln(...interface{})
	// Errorf formatted logs a message at level Error.
	Errorf(string, ...interface{})

	// Fatal logs a message at level Fatal and than call os.exit().
	Fatal(...interface{})
	// Fatalln logs a message at level Fatal and than call os.exit().
	Fatalln(...interface{})
	// Fatalf formatted logs a message at level Fatal and than call os.exit().
	Fatalf(string, ...interface{})

	// Panic logs a message at level Panic and than call panic().
	Panic(...interface{})
	// Panicln logs a message at level Panic and than call panic().
	Panicln(...interface{})
	// Panicf formatted logs a message at level Panic and than call panic().
	Panicf(string, ...interface{})

	// SetOutput sets the output destination for the logger.
	SetOutput(w io.Writer)
}

Logger is the interface for loggers used in the Insolar components.

type LogicCallContext added in v0.0.6

type LogicCallContext struct {
	Callee *RecordRef // Contract that was called
	Class  *RecordRef // Class of the callee
	Parent *RecordRef // Parent of the callee
	Caller *RecordRef // Contract that made the call
	Time   time.Time  // Time when call was made
	Pulse  Pulse      // Number of the pulse
}

LogicCallContext is a context of contract execution

type LogicRunner

type LogicRunner interface {
	Execute(Message) (res Reply, err error)
	OnPulse(Pulse) error
}

LogicRunner is an interface that should satisfy logic executor

type MachineLogicExecutor

type MachineLogicExecutor interface {
	CallMethod(ctx *LogicCallContext, code RecordRef, data []byte, method string, args Arguments) (newObjectState []byte, methodResults Arguments, err error)
	CallConstructor(ctx *LogicCallContext, code RecordRef, name string, args Arguments) (objectState []byte, err error)
	Stop() error
}

MachineLogicExecutor is an interface for implementers of one particular machine type

type MachineType

type MachineType int

MachineType is a type of virtual machine

const (
	MachineTypeNotExist             = 0
	MachineTypeBuiltin  MachineType = iota + 1
	MachineTypeGoPlugin

	MachineTypesLastID
)

Real constants of MachineType

type Message

type Message interface {
	// Type returns message type.
	Type() MessageType
	// Target returns target for this message. If nil, Message will be sent for all actors for the role returned by
	// Role method.
	Target() *RecordRef
	// TargetRole returns jet role to actors of which Message should be sent.
	TargetRole() JetRole
	// GetCaller returns initiator of this event.
	GetCaller() *RecordRef
}

Message is a routable packet, ATM just a method call

type MessageBus added in v0.4.0

type MessageBus interface {
	// Send an `Message` and get a `Reply` or error from remote host.
	Send(Message) (Reply, error)
	// SendAsync sends an `Message` to remote host.
	SendAsync(Message)
	// Register saves message handler in the registry. Only one handler can be registered for a message type.
	Register(p MessageType, handler MessageHandler) error
}

MessageBus interface

type MessageHandler added in v0.4.0

type MessageHandler func(Message) (Reply, error)

MessageHandler is a function for message handling. It should be registered via Register method.

type MessageType added in v0.4.0

type MessageType byte

MessageType is an enum type of message.

type Network

type Network interface {
	// SendMessage sends a message.
	SendMessage(nodeID RecordRef, method string, msg Message) ([]byte, error)
	// SendCascadeMessage sends a message.
	SendCascadeMessage(data Cascade, method string, msg Message) error
	// GetAddress returns an origin address.
	GetAddress() string
	// RemoteProcedureRegister is remote procedure register func.
	RemoteProcedureRegister(name string, method RemoteProcedure)
	// GetNodeID returns current node id.
	GetNodeID() RecordRef
}

Network is interface for network modules facade.

type NodeState added in v0.4.0

type NodeState uint8

NodeState is the state of the node

type ObjectDescriptor

type ObjectDescriptor interface {
	// HeadRef returns head reference to represented object record.
	HeadRef() *RecordRef

	// StateRef returns reference to object state record.
	StateRef() *RecordRef

	// Memory fetches object memory from storage.
	Memory() []byte

	// ClassDescriptor returns descriptor for fetching object's class data.
	ClassDescriptor(state *RecordRef) (ClassDescriptor, error)

	// Children returns object's children references.
	Children() RefIterator
}

ObjectDescriptor represents meta info required to fetch all object data.

type Pulse added in v0.2.0

type Pulse struct {
	PulseNumber     PulseNumber
	NextPulseNumber PulseNumber
	Entropy         Entropy
	Signs           map[string]PulseSenderConfirmation
}

Pulse is base data structure for a pulse.

func (*Pulse) PulseDuration added in v0.4.0

func (p *Pulse) PulseDuration() time.Duration

type PulseManager added in v0.2.0

type PulseManager interface {
	// Current returns current pulse structure.
	Current() (*Pulse, error)

	// Set set's new pulse and closes current jet drop.
	Set(pulse Pulse) error
}

PulseManager provides Ledger's methods related to Pulse.

type PulseNumber added in v0.0.6

type PulseNumber uint32

PulseNumber is a sequential number of Pulse. Upper 2 bits are reserved for use in references (scope), must be zero otherwise. Valid Absolute PulseNum must be >65536. If PulseNum <65536 it is a relative PulseNum

func Bytes2PulseNumber added in v0.2.0

func Bytes2PulseNumber(buf []byte) PulseNumber

Bytes2PulseNumber deserializes pulse number.

func CalculatePulseNumber added in v0.4.0

func CalculatePulseNumber(now time.Time) PulseNumber

func (PulseNumber) Bytes added in v0.2.0

func (pn PulseNumber) Bytes() []byte

Bytes serializes pulse number.

type PulseSenderConfirmation added in v0.4.0

type PulseSenderConfirmation struct {
	ChosenPublicKey string
	Signature       []byte
}

Information about pulse's confirmations

type RecordID added in v0.4.0

type RecordID [RecordIDSize]byte

RecordID is a unified record ID.

type RecordRef

type RecordRef [RecordRefSize]byte

RecordRef is a unified record reference.

func NewRefFromBase58 added in v0.2.0

func NewRefFromBase58(str string) RecordRef

NewRefFromBase58 deserializes reference from base58 encoded string.

func RandomRef added in v0.4.0

func RandomRef() RecordRef

RandomRef generates random RecordRef

func (RecordRef) Domain

func (ref RecordRef) Domain() RecordID

Domain returns domain ID part of reference.

func (RecordRef) Equal

func (ref RecordRef) Equal(other RecordRef) bool

Equal checks if reference points to the same record.

func (RecordRef) String

func (ref RecordRef) String() string

String outputs base58 RecordRef representation.

type RefIterator added in v0.0.6

type RefIterator interface {
	Next() (RecordRef, error)
	HasNext() bool
}

RefIterator is used for iteration over affined children(parts) of container.

type RemoteProcedure

type RemoteProcedure func(args [][]byte) ([]byte, error)

RemoteProcedure is remote procedure call function.

type Reply added in v0.4.0

type Reply interface {
	// Type returns message type.
	Type() ReplyType
}

Reply for an `Message`

type ReplyType added in v0.4.0

type ReplyType byte

ReplyType is an enum type of message reply.

Directories

Path Synopsis
Package message represents message that messagebus can route
Package message represents message that messagebus can route
Package reply represents responses to messages of the messagebus
Package reply represents responses to messages of the messagebus

Jump to

Keyboard shortcuts

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