model

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

model contains data structures canonical to all layers in nuts-network

Index

Constants

View Source
const HashSize = 20

HashSize holds the size of hashes used on the network.

Variables

This section is empty.

Functions

func MarshalDocumentTime added in v0.15.3

func MarshalDocumentTime(ts time.Time) int64

MarshalDocumentTime converts a document's time.Time to unix nanoseconds.

func UnmarshalDocumentTime added in v0.15.3

func UnmarshalDocumentTime(ns int64) time.Time

UnmarshalDocumentTime converts a document's timestamp in unix nanoseconds to time.Time.

Types

type Document

type Document struct {
	// Hash contains the hash of the document (which is calculated using its type, timestamp and contents).
	Hash Hash
	// Type contains a key describing what the document holds (e.g. 'nuts.node-info'). It is free format.
	Type string
	// Timestamp holds the moment the document was created. When serialized (for storage or transport on the network) it is converted to UTC and represented in Unix nanoseconds.
	Timestamp time.Time
}

Document describes a document on the network.

func (Document) Clone

func (d Document) Clone() Document

Clone makes a deep copy of the document and returns it.

type DocumentDescriptor

type DocumentDescriptor struct {
	Document
	// HasContents indicates whether we have the contents of the document.
	HasContents bool
	// ConsistencyHash contains the actual consistency hash for the document.
	ConsistencyHash Hash
}

DocumentDescriptor is just a Document with often-required properties added (HasContents indicator) to optimize access to the document storage.

type Hash

type Hash [HashSize]byte

Hash is a type that holds a hash used on the network.

func CalculateDocumentHash

func CalculateDocumentHash(docType string, timestamp time.Time, contents []byte) Hash

CalculateDocumentHash calculates the hash for a Document in a canonicalized manner.

func EmptyHash

func EmptyHash() Hash

EmptyHash returns a Hash that is empty (initialized with zeros).

func MakeConsistencyHash

func MakeConsistencyHash(h1 Hash, h2 Hash) Hash

MakeConsistencyHash calculates a consistency hash for the given 2 input Hashes and returns it.

func ParseHash

func ParseHash(input string) (Hash, error)

ParseHash parses the given input string as Hash. If the input is invalid and can't be parsed as Hash, an error is returned.

func SliceToHash added in v0.15.2

func SliceToHash(slice []byte) Hash

SliceToHash converts a byte slice to a Hash, returning a copy.

func (Hash) Clone

func (h Hash) Clone() Hash

Clone returns a copy of the Hash.

func (Hash) Compare added in v0.15.2

func (h Hash) Compare(other Hash) int

Compare compares this Hash to another Hash using bytes.Compare.

func (Hash) Empty

func (h Hash) Empty() bool

Empty tests whether the Hash is empty (all zeros).

func (Hash) Equals

func (h Hash) Equals(other Hash) bool

Equals determines whether the given Hash is exactly the same (bytes match).

func (Hash) Slice added in v0.15.2

func (h Hash) Slice() []byte

Slice returns the Hash as a slice. It does not copy the array.

func (Hash) String

func (h Hash) String() string

String returns the Hash in serialized (and human-readable) form.

type NodeID

type NodeID string

NodeID is a self-proclaimed unique identifier for nodes on the network.

func (NodeID) Empty

func (n NodeID) Empty() bool

Empty checks whether the NodeID is empty (empty string).

func (NodeID) String

func (n NodeID) String() string

String returns the NodeID as string.

type NodeInfo

type NodeInfo struct {
	// ID holds the NodeID by which we know the node.
	ID NodeID
	// Address holds the remote address of the node.
	Address string
}

NodeInfo describes a known remote node on the network.

func (NodeInfo) String

func (n NodeInfo) String() string

String returns the NodeInfo in human-readable format.

type PeerID

type PeerID string

PeerID identifies a peer (connected node) on the network

func GetPeerID

func GetPeerID(addr string) PeerID

GetPeerID constructs a PeerID given its remote address.

Jump to

Keyboard shortcuts

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