boson

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: BSD-3-Clause Imports: 7 Imported by: 58

Documentation

Overview

Package boson contains most basic and general Aurora concepts.

Index

Constants

View Source
const (
	SpanSize                = 8
	SectionSize             = 32
	Branches                = 128 * 64
	EncryptedBranches       = Branches / 2
	BmtBranches             = 128 * 64               // sectionSize * branches determines the maximum chunk size hashed using the tree
	ChunkSize               = SectionSize * Branches // enlarge a minimal chunk size to 256k
	HashSize                = 32
	MaxPO             uint8 = 31
	ExtendedPO        uint8 = MaxPO + 5
	MaxBins                 = MaxPO + 1
	ChunkWithSpanSize       = ChunkSize + SpanSize
)

Variables

View Source
var (
	ErrInvalidChunk = errors.New("invalid chunk")
)
View Source
var (
	NewHasher = sha3.NewLegacyKeccak256
)
View Source
var ZeroAddress = NewAddress(nil)

ZeroAddress is the address that has no value.

Functions

func Distance

func Distance(x, y []byte) (*big.Int, error)

Distance returns the distance between address x and address y as a (comparable) big integer using the distance metric defined in the boson specification. Fails if not all addresses are of equal length.

func DistanceCmp

func DistanceCmp(a, x, y []byte) (int, error)

DistanceCmp compares x and y to a in terms of the distance metric defined in the boson specfication. it returns:

1 if x is closer to a than y
0 if x and y are equally far apart from a (this means that x and y are the same address)
-1 if x is farther from a than y

Fails if not all addresses are of equal length.

func DistanceRaw

func DistanceRaw(x, y []byte) ([]byte, error)

DistanceRaw returns the distance between address x and address y in big-endian binary format using the distance metric defined in the boson specfication. Fails if not all addresses are of equal length.

func ExtendedProximity

func ExtendedProximity(one, other []byte) (ret uint8)

func Proximity

func Proximity(one, other []byte) (ret uint8)

Proximity returns the proximity order of the MSB distance between x and y

The distance metric MSB(x, y) of two equal length byte sequences x an y is the value of the binary integer cast of the x^y, ie., x and y bitwise xor-ed. the binary cast is big endian: most significant bit first (=MSB).

Proximity(x, y) is a discrete logarithmic scaling of the MSB distance. It is defined as the reverse rank of the integer part of the base 2 logarithm of the distance. It is calculated by counting the number of common leading zeros in the (MSB) binary representation of the x^y.

(0 farthest, 255 closest, 256 self)

Types

type Address

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

Address represents an address in Aurora metric space of Node and Chunk addresses.

func MustParseHexAddress

func MustParseHexAddress(s string) Address

MustParseHexAddress returns an Address from a hex-encoded string representation, and panics if there is a parse error.

func NewAddress

func NewAddress(b []byte) Address

NewAddress constructs Address from a byte slice.

func ParseHexAddress

func ParseHexAddress(s string) (a Address, err error)

ParseHexAddress returns an Address from a hex-encoded string representation.

func (Address) ByteString

func (a Address) ByteString() string

ByteString returns raw Address string without encoding.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns bytes representation of the Address.

func (Address) Closer

func (a Address) Closer(x Address, y Address) (bool, error)

Closer returns if 'a' is closer to x than y

func (Address) Equal

func (a Address) Equal(b Address) bool

Equal returns true if two addresses are identical.

func (Address) IsZero

func (a Address) IsZero() bool

IsZero returns true if the Address is not set to any value.

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON-encoded representation of Address.

func (Address) MemberOf

func (a Address) MemberOf(addrs []Address) bool

MemberOf returns true if the address is a member of the provided set.

func (Address) String

func (a Address) String() string

String returns a hex-encoded representation of the Address.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON sets Address to a value from JSON-encoded representation.

type AddressIterFunc

type AddressIterFunc func(address Address) error

AddressIterFunc is a callback on every address that is found by the iterator.

type Chunk

type Chunk interface {
	Address() Address
	Data() []byte
	PinCounter() uint64
	WithPinCounter(p uint64) Chunk
	TagID() uint32
	WithTagID(t uint32) Chunk
	Equal(Chunk) bool
}

func NewChunk

func NewChunk(addr Address, data []byte) Chunk

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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