Documentation ¶
Index ¶
- Constants
- Variables
- func AliaserAliasClashTest(require *require.Assertions, _ AliaserReader, w AliaserWriter)
- func AliaserAliasesEmptyTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
- func AliaserAliasesTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func AliaserLookupErrorTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
- func AliaserLookupTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func AliaserPrimaryAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func AliaserRemoveAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
- func EqualSubset(start, stop int, id1, id2 ID) bool
- func FirstDifferenceSubset(start, stop int, id1, id2 ID) (int, bool)
- func GetRelevantAliases(aliaser Aliaser, ids []ID) (map[ID][]string, error)
- func ShortIDsToStrings(ids []ShortID) []string
- type Aliaser
- type AliaserReader
- type AliaserWriter
- type ID
- func (id ID) Bit(i uint) int
- func (id ID) Hex() string
- func (id ID) Less(other ID) bool
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id ID) Prefix(prefixes ...uint64) ID
- func (id ID) String() string
- func (id *ID) UnmarshalJSON(b []byte) error
- func (id *ID) UnmarshalText(text []byte) error
- func (id ID) XOR(other ID) ID
- type NodeID
- type RequestID
- type ShortID
- func (id ShortID) Bytes() []byte
- func (id ShortID) Hex() string
- func (id ShortID) Less(other ShortID) bool
- func (id ShortID) MarshalJSON() ([]byte, error)
- func (id ShortID) MarshalText() ([]byte, error)
- func (id ShortID) PrefixedString(prefix string) string
- func (id ShortID) String() string
- func (id *ShortID) UnmarshalJSON(b []byte) error
- func (id *ShortID) UnmarshalText(text []byte) error
Constants ¶
const ( NodeIDPrefix = "NodeID-" NodeIDLen = ShortIDLen )
const BitsPerByte = 8
BitsPerByte is the number of bits per byte
const (
IDLen = 32
)
const NumBits = 256
NumBits is the number of bits this patricia tree manages
const ShortIDLen = 20
Variables ¶
var AliasTests = []func(require *require.Assertions, r AliaserReader, w AliaserWriter){ AliaserLookupErrorTest, AliaserLookupTest, AliaserAliasesEmptyTest, AliaserAliasesTest, AliaserPrimaryAliasTest, AliaserAliasClashTest, AliaserRemoveAliasTest, }
var ( // Empty is a useful all zero value Empty = ID{} )
var (
EmptyNodeID = NodeID{}
)
var (
ErrNoIDWithAlias = errors.New("there is no ID with alias")
)
var (
ShortEmpty = ShortID{}
)
ShortEmpty is a useful all zero value
Functions ¶
func AliaserAliasClashTest ¶
func AliaserAliasClashTest(require *require.Assertions, _ AliaserReader, w AliaserWriter)
func AliaserAliasesEmptyTest ¶
func AliaserAliasesEmptyTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
func AliaserAliasesTest ¶
func AliaserAliasesTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func AliaserLookupErrorTest ¶
func AliaserLookupErrorTest(require *require.Assertions, r AliaserReader, _ AliaserWriter)
func AliaserLookupTest ¶
func AliaserLookupTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func AliaserPrimaryAliasTest ¶
func AliaserPrimaryAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func AliaserRemoveAliasTest ¶
func AliaserRemoveAliasTest(require *require.Assertions, r AliaserReader, w AliaserWriter)
func EqualSubset ¶
EqualSubset takes in two indices and two ids and returns if the ids are equal from bit start to bit end (non-inclusive). Bit indices are defined as: [7 6 5 4 3 2 1 0] [15 14 13 12 11 10 9 8] ... [255 254 253 252 251 250 249 248] Where index 7 is the MSB of byte 0.
func FirstDifferenceSubset ¶
FirstDifferenceSubset takes in two indices and two ids and returns the index of the first difference between the ids inside bit start to bit end (non-inclusive). Bit indices are defined above
func GetRelevantAliases ¶
GetRelevantAliases returns the aliases with the redundant identity alias removed (each id is aliased to at least itself).
func ShortIDsToStrings ¶ added in v1.8.4
ShortIDsToStrings converts an array of shortIDs to an array of their string representations
Types ¶
type Aliaser ¶
type Aliaser interface { AliaserReader AliaserWriter // PrimaryAliasOrDefault returns the first alias of [id], or ID string as a // default if no alias exists PrimaryAliasOrDefault(id ID) string }
Aliaser allows one to give an ID aliases and lookup the aliases given to an ID.
func NewAliaser ¶
func NewAliaser() Aliaser
type AliaserReader ¶
type AliaserReader interface { // Lookup returns the ID associated with alias Lookup(alias string) (ID, error) // PrimaryAlias returns the first alias of [id] PrimaryAlias(id ID) (string, error) // Aliases returns the aliases of an ID Aliases(id ID) ([]string, error) }
AliaserReader allows one to lookup the aliases given to an ID.
type AliaserWriter ¶
type AliaserWriter interface { // Alias gives [id] the alias [alias] Alias(id ID, alias string) error // RemoveAliases of the provided ID RemoveAliases(id ID) }
AliaserWriter allows one to give an ID aliases. An ID can have arbitrarily many aliases; two IDs may not have the same alias.
type ID ¶
ID wraps a 32 byte hash used as an identifier
func FromString ¶
FromString is the inverse of ID.String()
func GenerateTestID ¶
func GenerateTestID() ID
GenerateTestID returns a new ID that should only be used for testing
func (ID) MarshalJSON ¶
func (ID) MarshalText ¶
func (ID) Prefix ¶
Prefix this id to create a more selective id. This can be used to store multiple values under the same key. For example: prefix1(id) -> confidence prefix2(id) -> vertex This will return a new id and not modify the original id.
func (*ID) UnmarshalJSON ¶
func (*ID) UnmarshalText ¶
type NodeID ¶ added in v1.8.4
type NodeID ShortID
func GenerateTestNodeID ¶ added in v1.8.4
func GenerateTestNodeID() NodeID
GenerateTestNodeID returns a new ID that should only be used for testing
func NodeIDFromCert ¶ added in v1.8.4
func NodeIDFromCert(cert *staking.Certificate) NodeID
func NodeIDFromString ¶ added in v1.8.4
NodeIDFromString is the inverse of NodeID.String()
func (NodeID) MarshalJSON ¶ added in v1.8.4
func (NodeID) MarshalText ¶ added in v1.8.4
func (*NodeID) UnmarshalJSON ¶ added in v1.8.4
func (*NodeID) UnmarshalText ¶ added in v1.8.4
type RequestID ¶ added in v1.9.2
type RequestID struct { // The node this request came from NodeID NodeID // The chain this request came from SourceChainID ID // The chain the expected response should come from DestinationChainID ID // The unique identifier for this request RequestID uint32 // The message opcode Op byte }
RequestID is a unique identifier for an in-flight request pending a response.
type ShortID ¶
type ShortID [ShortIDLen]byte
ShortID wraps a 20 byte hash as an identifier
func GenerateTestShortID ¶
func GenerateTestShortID() ShortID
GenerateTestShortID returns a new ID that should only be used for testing
func ShortFromPrefixedString ¶
ShortFromPrefixedString returns a ShortID assuming the cb58 format is prefixed
func ShortFromString ¶
ShortFromString is the inverse of ShortID.String()
func (ShortID) Bytes ¶
Bytes returns the 20 byte hash as a slice. It is assumed this slice is not modified.
func (ShortID) MarshalJSON ¶
func (ShortID) MarshalText ¶ added in v1.8.4
func (ShortID) PrefixedString ¶
PrefixedString returns the String representation with a prefix added