Documentation
¶
Index ¶
- Constants
- Variables
- func AppendIfAbsent[T Equality](slice []T, a ...T) []T
- func Exclude[T Equality](lst []T, ex []T) []T
- func ExcludeIf[T Equality](lst []T, vfunc func(v T) bool) []T
- func ExecWithTimeout(ctx context.Context, fn func(), timeout time.Duration) error
- func IntToByteArray(num int) []byte
- func IsOrdered(start Key, startInclusive bool, val Key, end Key, endInclusive bool) bool
- func IsSubsetOf[T Equality](curKNodes []T, queried []T) bool
- func LessThanExists(lst []int, x int) bool
- func MaxID() peer.ID
- func PickRandomly[T any](arg []T) T
- func RandomID() peer.ID
- func ReverseSlice(data interface{})
- func SliceString[T fmt.Stringer](args []T) string
- func ZeroID() peer.ID
- type AbstractEvent
- func (ev *AbstractEvent) IsRequest() bool
- func (ev *AbstractEvent) IsResponse() bool
- func (ev *AbstractEvent) IsVerified() bool
- func (ev *AbstractEvent) Originator() Node
- func (ev *AbstractEvent) OriginatorPubKey() []byte
- func (ev *AbstractEvent) OriginatorSign() []byte
- func (ev *AbstractEvent) Receiver() Node
- func (ev *AbstractEvent) SendTime() int64
- func (ev *AbstractEvent) Sender() Node
- func (ev *AbstractEvent) SetReceiver(n Node)
- func (ev *AbstractEvent) SetRequest(v bool)
- func (ev *AbstractEvent) SetSendTime(t int64)
- func (ev *AbstractEvent) SetSender(n Node)
- func (ev *AbstractEvent) SetTime(t int64)
- func (ev *AbstractEvent) SetVerified(v bool)
- func (ev *AbstractEvent) Time() int64
- type AbstractSchedEvent
- func (se *AbstractSchedEvent) Cancel()
- func (ev *AbstractSchedEvent) Encode() *p2p.Message
- func (se *AbstractSchedEvent) IsCanceled() bool
- func (se *AbstractSchedEvent) Job() func()
- func (se *AbstractSchedEvent) ProcessRequest(ctx context.Context, n Node) SchedEvent
- func (se *AbstractSchedEvent) Run(ctx context.Context, n Node) error
- func (se *AbstractSchedEvent) SetCanceled(c bool)
- func (se *AbstractSchedEvent) SetJob(j func())
- func (ev *AbstractSchedEvent) String() string
- type AsyncJobEvent
- type Equality
- type Event
- type EventExecutor
- type EventQueue
- type FSKeystore
- type FloatKey
- type IdKey
- type IntKey
- type Key
- func NewFloatKeyFromBytes(arg []byte) Key
- func NewIdKeyFromBytes(arg []byte) Key
- func NewIntKeyFromBytes(arr []byte) Key
- func NewKey(key *pb.Key) Key
- func NewRandomUnifiedKey() Key
- func NewRangeKeyFromBytes(arg []byte) Key
- func NewStringKeyFromBytes(arg []byte) Key
- func NewUnifiedKey(v *big.Int, id peer.ID) Key
- func NewUnifiedKeyBetween(start, end *UnifiedKey) Key
- func NewUnifiedKeyFromByteValue(value []byte, id peer.ID) Key
- func NewUnifiedKeyFromBytes(arr []byte) Key
- func NewUnifiedKeyFromIdKey(id IdKey) Key
- func NewUnifiedKeyFromInt(i int, id peer.ID) Key
- func NewUnifiedKeyFromString(str string, id peer.ID) Key
- func NewUnifiedKeyFromStringWithJitter(str string) Key
- type Keystore
- type LocalNode
- func (n *LocalNode) Addrs() []ma.Multiaddr
- func (an *LocalNode) App() interface{}
- func (n *LocalNode) Close() error
- func (n *LocalNode) Encode() *pb.Peer
- func (n *LocalNode) Equals(o Node) bool
- func (n *LocalNode) Id() peer.ID
- func (n *LocalNode) Key() Key
- func (n *LocalNode) MV() *MembershipVector
- func (n *LocalNode) MessageIdPrefix() string
- func (n *LocalNode) Name() string
- func (an *LocalNode) Sched(ev SchedEvent, time int64)
- func (an *LocalNode) Send(ctx context.Context, ev SchedEvent, sign bool) error
- func (an *LocalNode) SetApp(app interface{})
- func (n *LocalNode) SetKey(key Key)
- func (n *LocalNode) SetMV(mv *MembershipVector)
- func (n *LocalNode) SetName(name string)
- func (n *LocalNode) String() string
- type MembershipVector
- func (mv *MembershipVector) CommonPrefixLength(another *MembershipVector) int
- func (mv *MembershipVector) Encode() []byte
- func (mv *MembershipVector) Equals(other *MembershipVector) bool
- func (mv *MembershipVector) Less(other *MembershipVector) bool
- func (mv *MembershipVector) LessOrEquals(other *MembershipVector) bool
- func (mv *MembershipVector) String() string
- type Node
- type RangeKey
- func (t *RangeKey) ContainsKey(k Key) bool
- func (t *RangeKey) Encode() *pb.Key
- func (t *RangeKey) End() Key
- func (t *RangeKey) EndExtent() Key
- func (t *RangeKey) EndInclusive() bool
- func (t *RangeKey) Equals(elem any) bool
- func (t *RangeKey) Less(elem interface{}) bool
- func (t *RangeKey) LessOrEquals(elem interface{}) bool
- func (t *RangeKey) SetEndExtent(key Key)
- func (t *RangeKey) SetStartExtent(key Key)
- func (t *RangeKey) Start() Key
- func (t *RangeKey) StartExtent() Key
- func (t *RangeKey) StartInclusive() bool
- func (t *RangeKey) String() string
- type SchedEvent
- type StringKey
- type UnifiedKey
- func (t *UnifiedKey) Encode() *p2p.Key
- func (t *UnifiedKey) Equals(elem any) bool
- func (t *UnifiedKey) GetBigInt() *big.Int
- func (t *UnifiedKey) ID() peer.ID
- func (t *UnifiedKey) Less(elem interface{}) bool
- func (t *UnifiedKey) LessOrEquals(elem interface{}) bool
- func (t *UnifiedKey) Pretty() string
- func (t *UnifiedKey) SetID(i peer.ID)
- func (t *UnifiedKey) String() string
- func (t *UnifiedKey) UnescapedString() string
- func (t *UnifiedKey) Value() []byte
Constants ¶
const ( JITTER_VALUE = 100000 UNIFIED_KEY_LENGTH = 512 // bits UNIFIED_KEY_SEP = ":" MOD_FACTOR = 10007 // prime number )
const ( DEBUG = "debug" INFO = "info" WARN = "warn" ERROR = "error" FATAL = "fatal" )
Log level constants
const (
DefaultAlpha = 2
)
Variables ¶
var ErrKeyExists = fmt.Errorf("key by that name already exists, refusing to overwrite")
ErrKeyExists is an error message returned when a key already exists
var ErrNoSuchKey = fmt.Errorf("no key by the given name was found")
ErrNoSuchKey is an error message returned when no key of a given name was found.
var GlobalEventExecutor = NewEventExecutor()
var MembershipVectorSize = 256
var NETWORK_LATENCY = int64(1)
Functions ¶
func AppendIfAbsent ¶
func AppendIfAbsent[T Equality](slice []T, a ...T) []T
func ExecWithTimeout ¶
func IntToByteArray ¶
func IsSubsetOf ¶
func LessThanExists ¶
func PickRandomly ¶
func PickRandomly[T any](arg []T) T
func ReverseSlice ¶
func ReverseSlice(data interface{})
func SliceString ¶
Types ¶
type AbstractEvent ¶
type AbstractEvent struct {
// contains filtered or unexported fields
}
func NewEvent ¶
func NewEvent(originator Node, originatorSign []byte, originatorPubKey []byte) *AbstractEvent
func NewEventNoAuthor ¶
func NewEventNoAuthor() *AbstractEvent
func (*AbstractEvent) IsRequest ¶
func (ev *AbstractEvent) IsRequest() bool
func (*AbstractEvent) IsResponse ¶
func (ev *AbstractEvent) IsResponse() bool
func (*AbstractEvent) IsVerified ¶
func (ev *AbstractEvent) IsVerified() bool
func (*AbstractEvent) Originator ¶
func (ev *AbstractEvent) Originator() Node
func (*AbstractEvent) OriginatorPubKey ¶
func (ev *AbstractEvent) OriginatorPubKey() []byte
func (*AbstractEvent) OriginatorSign ¶
func (ev *AbstractEvent) OriginatorSign() []byte
func (*AbstractEvent) Receiver ¶
func (ev *AbstractEvent) Receiver() Node
func (*AbstractEvent) SendTime ¶
func (ev *AbstractEvent) SendTime() int64
func (*AbstractEvent) Sender ¶
func (ev *AbstractEvent) Sender() Node
func (*AbstractEvent) SetReceiver ¶
func (ev *AbstractEvent) SetReceiver(n Node)
func (*AbstractEvent) SetRequest ¶
func (ev *AbstractEvent) SetRequest(v bool)
func (*AbstractEvent) SetSendTime ¶
func (ev *AbstractEvent) SetSendTime(t int64)
func (*AbstractEvent) SetSender ¶
func (ev *AbstractEvent) SetSender(n Node)
func (*AbstractEvent) SetTime ¶
func (ev *AbstractEvent) SetTime(t int64)
func (*AbstractEvent) SetVerified ¶
func (ev *AbstractEvent) SetVerified(v bool)
func (*AbstractEvent) Time ¶
func (ev *AbstractEvent) Time() int64
type AbstractSchedEvent ¶
type AbstractSchedEvent struct {
AbstractEvent
// contains filtered or unexported fields
}
func NewSchedEvent ¶
func NewSchedEvent(author Node, authorSign []byte, authorPubKey []byte) *AbstractSchedEvent
func NewSchedEventWithJob ¶
func NewSchedEventWithJob(job func()) *AbstractSchedEvent
func (*AbstractSchedEvent) Cancel ¶
func (se *AbstractSchedEvent) Cancel()
func (*AbstractSchedEvent) Encode ¶
func (ev *AbstractSchedEvent) Encode() *p2p.Message
func (*AbstractSchedEvent) IsCanceled ¶
func (se *AbstractSchedEvent) IsCanceled() bool
func (*AbstractSchedEvent) Job ¶
func (se *AbstractSchedEvent) Job() func()
func (se *AbstractSchedEvent) Job() func(se SchedEvent, node Node) {
func (*AbstractSchedEvent) ProcessRequest ¶
func (se *AbstractSchedEvent) ProcessRequest(ctx context.Context, n Node) SchedEvent
func (*AbstractSchedEvent) Run ¶
func (se *AbstractSchedEvent) Run(ctx context.Context, n Node) error
func (*AbstractSchedEvent) SetCanceled ¶
func (se *AbstractSchedEvent) SetCanceled(c bool)
func (*AbstractSchedEvent) SetJob ¶
func (se *AbstractSchedEvent) SetJob(j func())
func (se *AbstractSchedEvent) SetJob(j func(se SchedEvent, node Node)) {
func (*AbstractSchedEvent) String ¶
func (ev *AbstractSchedEvent) String() string
type AsyncJobEvent ¶
type AsyncJobEvent struct {
AbstractSchedEvent
// contains filtered or unexported fields
}
func (*AsyncJobEvent) Run ¶
func (aj *AsyncJobEvent) Run(node Node) error
type Event ¶
type Event interface {
Originator() Node
OriginatorSign() []byte
OriginatorPubKey() []byte
Sender() Node
SetSender(Node)
Receiver() Node
SetReceiver(Node)
SendTime() int64
SetSendTime(int64)
Time() int64
SetTime(int64)
Encode() *p2p.Message
SetVerified(bool)
IsVerified() bool
SetRequest(bool)
IsRequest() bool
IsResponse() bool
}
type EventExecutor ¶
type EventExecutor struct {
EventCount int
// contains filtered or unexported fields
}
func NewEventExecutor ¶
func NewEventExecutor() *EventExecutor
func (*EventExecutor) AwaitFinish ¶
func (ee *EventExecutor) AwaitFinish() bool
func (*EventExecutor) RegisterEvent ¶
func (ee *EventExecutor) RegisterEvent(ev SchedEvent, latency int64) error
func (*EventExecutor) Reset ¶
func (ee *EventExecutor) Reset()
func (*EventExecutor) RunForever ¶
func (ee *EventExecutor) RunForever()
func (*EventExecutor) Sim ¶
func (ee *EventExecutor) Sim(simTime int64, verbose bool)
func (*EventExecutor) Stop ¶
func (ee *EventExecutor) Stop()
type EventQueue ¶
type EventQueue []SchedEvent
func (EventQueue) Len ¶
func (eq EventQueue) Len() int
func (EventQueue) Less ¶
func (eq EventQueue) Less(i, j int) bool
func (*EventQueue) Pop ¶
func (eq *EventQueue) Pop() interface{}
func (*EventQueue) Push ¶
func (eq *EventQueue) Push(x interface{})
func (EventQueue) Swap ¶
func (eq EventQueue) Swap(i, j int)
type FSKeystore ¶
type FSKeystore struct {
// contains filtered or unexported fields
}
FSKeystore is a keystore backed by files in a given directory stored on disk.
func NewFSKeystore ¶
func NewFSKeystore(dir string) (*FSKeystore, error)
NewFSKeystore returns a new filesystem-backed keystore.
func (*FSKeystore) Delete ¶
func (ks *FSKeystore) Delete(name string) error
Delete removes a key from the Keystore
func (*FSKeystore) Get ¶
func (ks *FSKeystore) Get(name string) (ci.PrivKey, error)
Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey otherwise.
func (*FSKeystore) Has ¶
func (ks *FSKeystore) Has(name string) (bool, error)
Has returns whether or not a key exists in the Keystore
func (*FSKeystore) List ¶
func (ks *FSKeystore) List() ([]string, error)
List return a list of key identifier
type Key ¶
type Key interface {
// Less reports whether the element is less than b
Less(elem interface{}) bool
// Equals reports whether the element equals to b
Equals(elem any) bool
// Suger.
LessOrEquals(elem interface{}) bool
String() string
Encode() *pb.Key
}
func NewFloatKeyFromBytes ¶
func NewIdKeyFromBytes ¶
func NewIntKeyFromBytes ¶
func NewRandomUnifiedKey ¶
func NewRandomUnifiedKey() Key
func NewRangeKeyFromBytes ¶
func NewStringKeyFromBytes ¶
func NewUnifiedKeyBetween ¶
func NewUnifiedKeyBetween(start, end *UnifiedKey) Key
func NewUnifiedKeyFromBytes ¶
func NewUnifiedKeyFromIdKey ¶
type Keystore ¶
type Keystore interface {
// Has returns whether or not a key exists in the Keystore
Has(string) (bool, error)
// Put stores a key in the Keystore, if a key with the same name already exists, returns ErrKeyExists
Put(string, ci.PrivKey) error
// Get retrieves a key from the Keystore if it exists, and returns ErrNoSuchKey
// otherwise.
Get(string) (ci.PrivKey, error)
// Delete removes a key from the Keystore
Delete(string) error
// List returns a list of key identifier
List() ([]string, error)
}
Keystore provides a key management interface
type LocalNode ¶
type LocalNode struct {
// contains filtered or unexported fields
}
func NewLocalNode ¶
func NewLocalNode(key Key, name string, mv *MembershipVector) *LocalNode
func (*LocalNode) MV ¶
func (n *LocalNode) MV() *MembershipVector
func (*LocalNode) MessageIdPrefix ¶
func (*LocalNode) Sched ¶
func (an *LocalNode) Sched(ev SchedEvent, time int64)
func (*LocalNode) SetMV ¶
func (n *LocalNode) SetMV(mv *MembershipVector)
type MembershipVector ¶
func NewMembershipVector ¶
func NewMembershipVector(alpha int) *MembershipVector
func NewMembershipVectorFromBinary ¶
func NewMembershipVectorFromBinary(bin []byte) *MembershipVector
func NewMembershipVectorFromId ¶
func NewMembershipVectorFromId(id string) *MembershipVector
Requires MembershipVectorSize = 320
func NewMembershipVectorLiteral ¶
func NewMembershipVectorLiteral(alpha int, literal []int) *MembershipVector
func (*MembershipVector) CommonPrefixLength ¶
func (mv *MembershipVector) CommonPrefixLength(another *MembershipVector) int
func (*MembershipVector) Encode ¶
func (mv *MembershipVector) Encode() []byte
returns the byte representation.
func (*MembershipVector) Equals ¶
func (mv *MembershipVector) Equals(other *MembershipVector) bool
func (*MembershipVector) Less ¶
func (mv *MembershipVector) Less(other *MembershipVector) bool
func (*MembershipVector) LessOrEquals ¶
func (mv *MembershipVector) LessOrEquals(other *MembershipVector) bool
func (*MembershipVector) String ¶
func (mv *MembershipVector) String() string
type Node ¶
type Node interface {
Key() Key
SetKey(Key)
MV() *MembershipVector
SetMV(*MembershipVector)
Name() string
SetName(string)
String() string
Addrs() []ma.Multiaddr
Id() peer.ID // ID as an Endpoint
Send(ctx context.Context, ev SchedEvent, sign bool) error
Encode() *pb.Peer
Close() error
App() interface{}
SetApp(interface{})
MessageIdPrefix() string
}
type RangeKey ¶
type RangeKey struct {
// contains filtered or unexported fields
}
func NewRangeKey ¶
start and end are not inclusive by default
func (*RangeKey) ContainsKey ¶
func (*RangeKey) EndInclusive ¶
func (*RangeKey) LessOrEquals ¶
func (*RangeKey) SetEndExtent ¶
func (*RangeKey) SetStartExtent ¶
func (*RangeKey) StartExtent ¶
func (*RangeKey) StartInclusive ¶
type SchedEvent ¶
type UnifiedKey ¶
type UnifiedKey struct {
// contains filtered or unexported fields
}
func (*UnifiedKey) Encode ¶
func (t *UnifiedKey) Encode() *p2p.Key
func (*UnifiedKey) Equals ¶
func (t *UnifiedKey) Equals(elem any) bool
func (*UnifiedKey) GetBigInt ¶
func (t *UnifiedKey) GetBigInt() *big.Int
func (*UnifiedKey) ID ¶
func (t *UnifiedKey) ID() peer.ID
func (*UnifiedKey) Less ¶
func (t *UnifiedKey) Less(elem interface{}) bool
func (*UnifiedKey) LessOrEquals ¶
func (t *UnifiedKey) LessOrEquals(elem interface{}) bool
func (*UnifiedKey) Pretty ¶
func (t *UnifiedKey) Pretty() string
func (*UnifiedKey) SetID ¶
func (t *UnifiedKey) SetID(i peer.ID)
func (*UnifiedKey) String ¶
func (t *UnifiedKey) String() string
func (*UnifiedKey) UnescapedString ¶
func (t *UnifiedKey) UnescapedString() string
func (*UnifiedKey) Value ¶
func (t *UnifiedKey) Value() []byte