id

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: BSD-2-Clause Imports: 7 Imported by: 150

Documentation

Overview

Contains the generic ID type, which is a byte array that represents an entity ID. The first bytes in the array contain the actual ID data while the last byte contains the ID type, which is either generic, gateway, node, or user. IDs can be hard coded or generated using a cryptographic function found in crypto.

Index

Constants

View Source
const (
	Generic = Type(iota)
	Gateway
	Node
	User
	NumTypes // Gives number of ID types
)

List of ID types

View Source
const (

	// Length of the full ID array
	ArrIDLen = dataLen + 1
)

Variables

View Source
var DummyUser = ID{100, 117, 109, 109, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(User)}

ID for a dummy user (ID data is the string "dummy")

View Source
var NotificationBot = ID{110, 111, 116, 105, 102, 105, 99, 97, 116, 105, 111,
	110, 45, 98, 111, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(Generic)}

ID for notification bot (ID data is the string "notification-bot")

View Source
var Permissioning = ID{80, 101, 114, 109, 105, 115, 115, 105, 111, 110, 105,
	110, 103, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(Generic)}

ID for permissioning (ID data is the string "Permissioning")

View Source
var TempGateway = ID{116, 109, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(Gateway)}

ID for a temporary gateway (ID data is the string "tmp")

View Source
var UDB = ID{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(User)}

ID for UDB (ID data is in the range of dummy IDs)

View Source
var ZeroUser = ID{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, byte(User)}

ID for a user with the ID data all zeroes

Functions

func CollidesWithHardCodedID

func CollidesWithHardCodedID(testID *ID) bool

CollidesWithHardCodedID searches if the given ID collides with any hard coded IDs. If it collides, then the function returns true. Otherwise, it returns false.

Types

type ID

type ID [ArrIDLen]byte

ID is an array holding the generic identifier. The first 32 bytes hold the ID data and the last byte holds the ID type.

func GetHardCodedIDs

func GetHardCodedIDs() (ids []*ID)

GetHardCodedIDs returns an array of all the hard coded IDs.

func NewIDListFromBytes

func NewIDListFromBytes(topology [][]byte) ([]*ID, error)

NewIDListFromBytes creates a list of IDs from a list of byte slices. On success, it returns a new list. On failure, it returns a nil list and an error.

func NewIdFromBytes

func NewIdFromBytes(data []byte, x interface{}) *ID

NewIdFromBytes creates a new ID from a copy of the data. It is similar to Unmarshal() but does not do any error checking. If the data is longer than ArrIDLen, then it is truncated. If it is shorter, then the remaining bytes are filled with zeroes. This function is for testing purposes only.

func NewIdFromString

func NewIdFromString(idString string, idType Type, x interface{}) *ID

NewIdFromString creates a new ID from the given string and type. If the string is longer than dataLen, then it is truncated. If it is shorter, then the remaining bytes are filled with zeroes. This function is for testing purposes only.

func NewIdFromUInt

func NewIdFromUInt(idUInt uint64, idType Type, x interface{}) *ID

NewIdFromUInt converts the specified uint64 into bytes and returns a new ID based off it with the specified ID type. The remaining space of the array is filled with zeros. This function is for testing purposes only.

func NewIdFromUInts

func NewIdFromUInts(idUInts [4]uint64, idType Type, x interface{}) *ID

NewIdFromUInt converts the specified uint64 array into bytes and returns a new ID based off it with the specified ID type. Unlike NewIdFromUInt(), the four uint64s provided fill the entire ID array. This function is for testing purposes only.

func Unmarshal

func Unmarshal(data []byte) (*ID, error)

Unmarshal takes in the ID wire format and copies the data into an ID.

func (*ID) Bytes

func (i *ID) Bytes() []byte

Bytes returns a copy of an ID as a byte slice. Note that Bytes() is used by Marshal() and any changes made here will affect how Marshal() functions.

func (*ID) Cmp

func (i *ID) Cmp(y *ID) bool

Cmp determines whether two IDs are the same. Returns true if they are equal and false otherwise.

func (*ID) DeepCopy

func (i *ID) DeepCopy() *ID

DeepCopy creates a new copy of an ID.

func (*ID) GetType

func (i *ID) GetType() Type

GetType returns the ID's type. It is the last byte of the array.

func (*ID) Marshal

func (i *ID) Marshal() []byte

Marshal takes an ID and copies the data into the wire format.

func (*ID) SetType

func (i *ID) SetType(idType Type)

SetType changes the ID type by setting the last byte to the specified type.

func (*ID) String

func (i *ID) String() string

String converts an ID to a string via base64 encoding.

type Round

type Round uint64

type Type

type Type byte

Type holds the numerical representation of the ID type.

func (Type) String

func (t Type) String() string

String is a stringer to get the name of the ID type.

Directories

Path Synopsis
The package idf contains the structure of the ID File.
The package idf contains the structure of the ID File.

Jump to

Keyboard shortcuts

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