record

package
v0.0.0-...-9f2e8a2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasType

func HasType(r Record, t Type) bool

HasType returns whether a Record r is of Type t.

func IsValid

func IsValid(r Record) (ok bool, err error)

IsValid checks a record's validity with the appropriate validator, and returns whether a Record is valid. err may be non nil if there is an error checking the validity. An error counts as invalid, so IsValid will always return ok == false when err != nil.

func Marshal

func Marshal(r Record) ([]byte, error)

Marshal returns a byte representation of a record.

func NodeHasRequiredLinks(nd *dag.Node, links []string) error

NodeHasRequiredLinks ensures a node has required links

func NodeHasType

func NodeHasType(nd *dag.Node, t Type) (bool, error)

NodeHasType returns whether a dag.Node nd is of Type t.

func Order

func Order(validator Validator, a, b Record) int

Order returns {-1, 0, 1} to order (and pick from) {a, b}. Orders by:

( cmp(a.Version(), b.Version()),     // 1) version numbers always take precedence
  validator.Order(a, b),             // 2) user's validator.Order(.) function
  cmp(Marshal(a), Marshal(b) )       // 3) worst case, order by raw bytes.

1) A higher version number _always_ takes precedence over a lower version number. Record systems could use version numbers primarily for delivering updates, but SHOULD still address ordering records with equal version numbers (multipler writer problem).

2) The user's validator's Order function is used next to determine the order of records. Thus the user may define ordering based on timestamps on the record, or on some (pure) computation based on the record.

3) In the worst case, records are orderered by cmp( Marshal(a), Marshal(b) ) to ensure there is _always_ a deterministic way to order records. This also lets the user define Validator.Order(.) functions to always return 0 and the record system _will still be deterministic_ (a very important property).

Types

type Record

type Record interface {
	// Node returns a DAG.Node representing the Record.
	Node() *dag.Node

	// Type returns the type of the record.
	Type() Type

	// Version returns the version number of a record.
	Version() int

	// Data returns data carried (or linked) by the record used in determining validity
	Validity() []byte

	// Value returns data carried (or linked) by the record to be used
	Value() []byte
}

Record is an object that stores some data relevant to a distributed system. It is a necesary part of most distributed systems -- it is a sort of "glue" that improves how they operate.

func UnmarshalFromSet

func UnmarshalFromSet(ts *TypeSet, buf []byte) (Record, error)

UnmarshalTypeSet returns a Record instance from its byte representation, acord to type chosen from given typeset.

func UnmarshalType

func UnmarshalType(t Type, buf []byte) (Record, error)

UnmarshalType returns a Record instance from its byte representation, acord to given type.

type Type

type Type interface {
	// Node returns a DAG.Node representing the record.Type.
	Node() *dag.Node

	// Validator returns an object that can determine the validity
	// of a Record, and that can order records deterministically.
	// The Validator is specific to this Type.
	Validator() Validator

	// New constructs a new record from given node.
	New(nd *dag.Node) (Record, error)
}

type TypeSet

type TypeSet struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TypeSet is a collection of Types, used to track types registered in the record system.

func (*TypeSet) Type

func (ts *TypeSet) Type(s string) Type

Type returns the type registered at given key

func (*TypeSet) Types

func (ts *TypeSet) Types() map[string]Type

Types returns the types registered (allowed)

type Validator

type Validator interface {

	// Type returns the type of the validator.
	Type() Type

	// Valid returns whether a Record is valid in present circumstances.
	// This could include checking correctness of the record (checking cryptographic
	// signatures, and the like), or some validity regarding external infrastructure
	// such as:
	// - PKIs (Public Key Infrastructures)  -- is a signature chain valid?
	// - TIs (Time Infrastructures) -- is this record valid _right now_?
	Valid(Record) (bool, error)

	// Order returns {-1, 0, 1} to order (and pick from) {a, b}.
	Order(a, b Record) int
}

Validator represents an algorithm for determining the validity of a Record, and to order records deterministically.

Directories

Path Synopsis
Package ipfs_iprs is a generated protocol buffer package.
Package ipfs_iprs is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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