member

package
v0.0.0-...-05bc493 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeBits                          = 4
	ModeFlagRestrictedBehavior OpMode = 4
	ModeFlagValidationWarning  OpMode = 2
	ModeFlagSuspendedOps       OpMode = 1

	ModeNormal                    OpMode = 0
	ModeSuspected                        = ModeFlagSuspendedOps
	ModePossibleFraud                    = ModeFlagValidationWarning
	ModePossibleFraudAndSuspected        = ModeFlagSuspendedOps | ModeFlagValidationWarning
	ModeRestrictedAnnouncement           = ModeFlagRestrictedBehavior
	ModeEvictedGracefully                = ModeFlagRestrictedBehavior | ModeFlagSuspendedOps
	ModeEvictedAsFraud                   = ModeFlagRestrictedBehavior | ModeFlagValidationWarning
	ModeEvictedAsSuspected               = ModeFlagRestrictedBehavior | ModeFlagValidationWarning | ModeFlagSuspendedOps
)
View Source
const MaxBitsetEntry = int(maxBitsetEntry)
View Source
const MaxLinearMemberPower = (0x1F+32)<<(0xFF>>5) - 32
View Source
const MaxNodeIndex = NodeIndexMask
View Source
const NodeIndexBits = 10 // DO NOT change it, otherwise nasty consequences will come
View Source
const NodeIndexMask = 1<<NodeIndexBits - 1

Variables

This section is empty.

Functions

func FmtBitsetEntry

func FmtBitsetEntry(s uint8) string

func LessByID

func LessByID(vNodeID, oNodeID node.ShortNodeID) bool

NB! Sorting is REVERSED

func SortingPowerRole

func SortingPowerRole(role PrimaryRole, pw Power, mode OpMode) uint16

Types

type BitsetEntry

type BitsetEntry uint8
const (
	BeHighTrust BitsetEntry = iota
	BeLimitedTrust
	BeBaselineTrust
	BeTimeout
	BeFraud
)

func (BitsetEntry) IsFraud

func (s BitsetEntry) IsFraud() bool

func (BitsetEntry) IsTimeout

func (s BitsetEntry) IsTimeout() bool

func (BitsetEntry) IsTrusted

func (s BitsetEntry) IsTrusted() bool

func (BitsetEntry) String

func (s BitsetEntry) String() string

type FullRank

type FullRank struct {
	InterimRank
	RoleCount uint16
	RolePower uint32
}

func (FullRank) AsMembershipRank

func (v FullRank) AsMembershipRank(totalCount Index) Rank

type Index

type Index uint16
const JoinerIndex Index = 0x8000

func AsIndex

func AsIndex(v int) Index

func AsIndexUint16

func AsIndexUint16(v uint16) Index

func (Index) AsInt

func (v Index) AsInt() int

func (Index) AsUint16

func (v Index) AsUint16() uint16

func (Index) AsUint32

func (v Index) AsUint32() uint32

func (Index) Ensure

func (v Index) Ensure() Index

func (Index) IsJoiner

func (v Index) IsJoiner() bool

func (Index) String

func (v Index) String() string

type InterimRank

type InterimRank struct {
	RankCursor
	SpecialRoles SpecialRole
	Power        Power
	OpMode       OpMode
}

type OpMode

type OpMode uint8 // 4-bit value

func (OpMode) AsUnit32

func (v OpMode) AsUnit32() uint32

func (OpMode) CanHaveState

func (v OpMode) CanHaveState() bool

func (OpMode) CanIntroduceJoiner

func (v OpMode) CanIntroduceJoiner(isJoiner bool) bool

func (OpMode) CanVote

func (v OpMode) CanVote() bool

func (OpMode) IsClean

func (v OpMode) IsClean() bool

func (OpMode) IsEvicted

func (v OpMode) IsEvicted() bool

func (OpMode) IsEvictedForcefully

func (v OpMode) IsEvictedForcefully() bool

func (OpMode) IsEvictedGracefully

func (v OpMode) IsEvictedGracefully() bool

func (OpMode) IsJustJoined

func (v OpMode) IsJustJoined() bool

func (OpMode) IsMistrustful

func (v OpMode) IsMistrustful() bool

func (OpMode) IsPowerless

func (v OpMode) IsPowerless() bool

func (OpMode) IsRestricted

func (v OpMode) IsRestricted() bool

func (OpMode) IsSuspended

func (v OpMode) IsSuspended() bool

func (OpMode) String

func (v OpMode) String() string

type Power

type Power uint8

func PowerOf

func PowerOf(linearValue uint16) Power

func (Power) AbsDelta

func (v Power) AbsDelta(o Power) uint16

func (Power) Delta

func (v Power) Delta(o Power) uint16

func (Power) PercentAndMin

func (v Power) PercentAndMin(percent int, min Power) Power

func (Power) ToLinearValue

func (v Power) ToLinearValue() uint16

type PowerSet

type PowerSet [4]Power

func PowerSetOf

func PowerSetOf(v uint32) PowerSet

func (PowerSet) AsUint32

func (v PowerSet) AsUint32() uint32

func (PowerSet) FindNearestValid

func (v PowerSet) FindNearestValid(p Power) Power

func (PowerSet) ForLevel

func (v PowerSet) ForLevel(lvl capacity.Level) Power

func (PowerSet) ForLevelWithPercents

func (v PowerSet) ForLevelWithPercents(lvl capacity.Level, pMinimal, pReduced, pNormal int) Power

func (PowerSet) IsAllowed

func (v PowerSet) IsAllowed(p Power) bool

func (PowerSet) IsEmpty

func (v PowerSet) IsEmpty() bool

func (PowerSet) IsValid

func (v PowerSet) IsValid() bool

func (PowerSet) Max

func (v PowerSet) Max() Power

func (PowerSet) Min

func (v PowerSet) Min() Power

func (PowerSet) Normalize

func (v PowerSet) Normalize() PowerSet

type PrimaryRole

type PrimaryRole uint8 // MUST BE 6-bit
const (
	PrimaryRoleInactive PrimaryRole = iota
	PrimaryRoleNeutral
	PrimaryRoleHeavyMaterial
	PrimaryRoleLightMaterial
	PrimaryRoleVirtual
	// PrimaryRoleCascade
	// PrimaryRoleRecrypt
	PrimaryRoleCount = iota

	PrimaryRoleUnknown = PrimaryRoleInactive
)

func GetPrimaryRoleFromString

func GetPrimaryRoleFromString(role string) PrimaryRole

GetPrimaryRoleFromString converts role from string to PrimaryRole.

func (PrimaryRole) Equal

func (v PrimaryRole) Equal(other PrimaryRole) bool

func (PrimaryRole) IsHeavyMaterial

func (v PrimaryRole) IsHeavyMaterial() bool

func (PrimaryRole) IsLightMaterial

func (v PrimaryRole) IsLightMaterial() bool

func (PrimaryRole) IsMaterial

func (v PrimaryRole) IsMaterial() bool

func (PrimaryRole) IsNeutral

func (v PrimaryRole) IsNeutral() bool

func (PrimaryRole) IsVirtual

func (v PrimaryRole) IsVirtual() bool

func (PrimaryRole) String

func (v PrimaryRole) String() string

type Rank

type Rank uint32
const JoinerRank Rank = 0

func NewMembershipRank

func NewMembershipRank(mode OpMode, pw Power, idx Index, count Index) Rank

func (Rank) GetIndex

func (v Rank) GetIndex() Index

func (Rank) GetMode

func (v Rank) GetMode() OpMode

func (Rank) GetPower

func (v Rank) GetPower() Power

func (Rank) GetTotalCount

func (v Rank) GetTotalCount() uint16

func (Rank) IsJoiner

func (v Rank) IsJoiner() bool

func (Rank) String

func (v Rank) String() string

type RankCursor

type RankCursor struct {
	Role           PrimaryRole
	RoleIndex      Index
	RolePowerIndex uint32
	TotalIndex     Index
}

type SortingRank

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

func NewSortingRank

func NewSortingRank(nodeID node.ShortNodeID, role PrimaryRole, pw Power, mode OpMode) SortingRank

func (SortingRank) GetNodeID

func (v SortingRank) GetNodeID() node.ShortNodeID

func (SortingRank) GetPower

func (v SortingRank) GetPower() Power

func (SortingRank) GetWorkingRole

func (v SortingRank) GetWorkingRole() PrimaryRole

func (SortingRank) IsWorking

func (v SortingRank) IsWorking() bool

func (SortingRank) Less

func (v SortingRank) Less(o SortingRank) bool

NB! Sorting is REVERSED

type SpecialRole

type SpecialRole uint8
const (
	SpecialRoleNone      SpecialRole = 0
	SpecialRoleDiscovery SpecialRole = 1 << iota
)

func (SpecialRole) Equal

func (v SpecialRole) Equal(other SpecialRole) bool

func (SpecialRole) IsDiscovery

func (v SpecialRole) IsDiscovery() bool

type StateBitset

type StateBitset []BitsetEntry

func (StateBitset) Len

func (b StateBitset) Len() int

type TrustLevel

type TrustLevel int8
const (
	FraudByBlacklist TrustLevel = -5 // in the blacklist
	FraudByNetwork   TrustLevel = -4 // >2/3 of network have indicated fraud
	FraudByNeighbors TrustLevel = -3 // >50% of neighborhood have indicated fraud
	FraudBySome      TrustLevel = -2 // some nodes have indicated fraud

	UnknownTrust TrustLevel = 0 // initial state

	TrustBySelf      TrustLevel = 1 // node has provided a liveness proof or NSH
	TrustBySome      TrustLevel = 2 // some nodes have indicated trust (same NSH)
	TrustByNeighbors TrustLevel = 3 // >50% of neighborhood have indicated trust
	TrustByNetwork   TrustLevel = 4 // >2/3 of network have indicated trust
	TrustByMandate   TrustLevel = 5 // on- or off-network node with a temporary mandate, e.g. pulsar or discovery
	TrustByCouncil   TrustLevel = 6 // on- or off-network node with a permanent mandate

	LocalSelfTrust  = TrustByNeighbors // MUST be not less than TrustByNeighbors
	FraudByThisNode = FraudByNeighbors // fraud is detected by this node
)

func UnwrapTrustRange

func UnwrapTrustRange(wrapped uint16) (lo, hi TrustLevel)

func (*TrustLevel) IsNegative

func (v *TrustLevel) IsNegative() bool

func (*TrustLevel) Update

func (v *TrustLevel) Update(newLevel TrustLevel) (modified bool)

Updates only to better/worse levels. Negative level of the same magnitude prevails.

func (*TrustLevel) UpdateKeepNegative

func (v *TrustLevel) UpdateKeepNegative(newLevel TrustLevel) (modified bool)

func (TrustLevel) WrapRange

func (v TrustLevel) WrapRange(hi TrustLevel) uint16

Jump to

Keyboard shortcuts

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