ayame

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JITTER_VALUE       = 100000
	UNIFIED_KEY_LENGTH = 512 // bits
	UNIFIED_KEY_SEP    = ":"
	MOD_FACTOR         = 10007 // prime number
)
View Source
const (
	DEBUG = "debug"
	INFO  = "info"
	WARN  = "warn"
	ERROR = "error"
	FATAL = "fatal"
)

Log level constants

View Source
const (
	DefaultAlpha = 2
)

Variables

View Source
var ErrKeyExists = fmt.Errorf("key by that name already exists, refusing to overwrite")

ErrKeyExists is an error message returned when a key already exists

View Source
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.

View Source
var GlobalEventExecutor = NewEventExecutor()
View Source
var MembershipVectorSize = 256
View Source
var NETWORK_LATENCY = int64(1)

Functions

func AppendIfAbsent

func AppendIfAbsent[T Equality](slice []T, a ...T) []T

func Exclude

func Exclude[T Equality](lst []T, ex []T) []T

func ExcludeIf

func ExcludeIf[T Equality](lst []T, vfunc func(v T) bool) []T

func ExecWithTimeout

func ExecWithTimeout(ctx context.Context, fn func(), timeout time.Duration) error

func IntToByteArray

func IntToByteArray(num int) []byte

func IsOrdered

func IsOrdered(start Key, startInclusive bool, val Key, end Key, endInclusive bool) bool

func IsSubsetOf

func IsSubsetOf[T Equality](curKNodes []T, queried []T) bool

func LessThanExists

func LessThanExists(lst []int, x int) bool

func MaxID

func MaxID() peer.ID

func PickRandomly

func PickRandomly[T any](arg []T) T

func RandomID

func RandomID() peer.ID

func ReverseSlice

func ReverseSlice(data interface{})

func SliceString

func SliceString[T fmt.Stringer](args []T) string

func ZeroID

func ZeroID() peer.ID

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 Equality

type Equality interface {
	Equals(any) bool
}

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

func (*FSKeystore) Put

func (ks *FSKeystore) Put(name string, k ci.PrivKey) error

Put stores a key in the Keystore, if a key with the same name already exists, returns ErrKeyExists

type FloatKey

type FloatKey float64

func (FloatKey) Encode

func (t FloatKey) Encode() *pb.Key

func (FloatKey) Equals

func (t FloatKey) Equals(elem any) bool

func (FloatKey) Less

func (t FloatKey) Less(elem interface{}) bool

func (FloatKey) LessOrEquals

func (t FloatKey) LessOrEquals(elem interface{}) bool

func (FloatKey) String

func (t FloatKey) String() string

type IdKey

type IdKey []byte

func NewIdKey

func NewIdKey(id peer.ID) IdKey

func NewStringIdKey

func NewStringIdKey(key string) IdKey

func (IdKey) Encode

func (t IdKey) Encode() *pb.Key

func (IdKey) Equals

func (t IdKey) Equals(elem any) bool

func (IdKey) Less

func (t IdKey) Less(elem interface{}) bool

func (IdKey) LessOrEquals

func (t IdKey) LessOrEquals(elem interface{}) bool

func (IdKey) String

func (t IdKey) String() string

type IntKey

type IntKey int

Integer Key

func (IntKey) Encode

func (t IntKey) Encode() *pb.Key

func (IntKey) Equals

func (t IntKey) Equals(elem any) bool

func (IntKey) Less

func (t IntKey) Less(elem interface{}) bool

func (IntKey) LessOrEquals

func (t IntKey) LessOrEquals(elem interface{}) bool

func (IntKey) String

func (t IntKey) String() string

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 NewFloatKeyFromBytes(arg []byte) Key

func NewIdKeyFromBytes

func NewIdKeyFromBytes(arg []byte) Key

func NewIntKeyFromBytes

func NewIntKeyFromBytes(arr []byte) Key

func NewKey

func NewKey(key *pb.Key) Key

func NewRandomUnifiedKey

func NewRandomUnifiedKey() Key

func NewRangeKeyFromBytes

func NewRangeKeyFromBytes(arg []byte) Key

func NewStringKeyFromBytes

func NewStringKeyFromBytes(arg []byte) Key

func NewUnifiedKey

func NewUnifiedKey(v *big.Int, id peer.ID) Key

func NewUnifiedKeyBetween

func NewUnifiedKeyBetween(start, end *UnifiedKey) Key

func NewUnifiedKeyFromByteValue

func NewUnifiedKeyFromByteValue(value []byte, id peer.ID) Key

func NewUnifiedKeyFromBytes

func NewUnifiedKeyFromBytes(arr []byte) Key

func NewUnifiedKeyFromIdKey

func NewUnifiedKeyFromIdKey(id IdKey) Key

func NewUnifiedKeyFromInt

func NewUnifiedKeyFromInt(i int, id peer.ID) Key

func NewUnifiedKeyFromString

func NewUnifiedKeyFromString(str string, id peer.ID) Key

func NewUnifiedKeyFromStringWithJitter

func NewUnifiedKeyFromStringWithJitter(str string) Key

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) Addrs

func (n *LocalNode) Addrs() []ma.Multiaddr

func (*LocalNode) App

func (an *LocalNode) App() interface{}

func (*LocalNode) Close

func (n *LocalNode) Close() error

func (*LocalNode) Encode

func (n *LocalNode) Encode() *pb.Peer

func (*LocalNode) Equals

func (n *LocalNode) Equals(o Node) bool

func (*LocalNode) Id

func (n *LocalNode) Id() peer.ID

func (*LocalNode) Key

func (n *LocalNode) Key() Key

func (*LocalNode) MV

func (n *LocalNode) MV() *MembershipVector

func (*LocalNode) MessageIdPrefix

func (n *LocalNode) MessageIdPrefix() string

func (*LocalNode) Name

func (n *LocalNode) Name() string

func (*LocalNode) Sched

func (an *LocalNode) Sched(ev SchedEvent, time int64)

func (*LocalNode) Send

func (an *LocalNode) Send(ctx context.Context, ev SchedEvent, sign bool) error

func (*LocalNode) SetApp

func (an *LocalNode) SetApp(app interface{})

func (*LocalNode) SetKey

func (n *LocalNode) SetKey(key Key)

func (*LocalNode) SetMV

func (n *LocalNode) SetMV(mv *MembershipVector)

func (*LocalNode) SetName

func (n *LocalNode) SetName(name string)

func (*LocalNode) String

func (n *LocalNode) String() string

type MembershipVector

type MembershipVector struct {
	Alpha int
	Val   []int
}

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

func NewRangeKey(start Key, startInclusive bool, end Key, endInclusive bool) *RangeKey

start and end are not inclusive by default

func NewUnifiedRangeKeyForPrefix

func NewUnifiedRangeKeyForPrefix(prefix string) *RangeKey

func (*RangeKey) ContainsKey

func (t *RangeKey) ContainsKey(k Key) bool

func (*RangeKey) Encode

func (t *RangeKey) Encode() *pb.Key

func (*RangeKey) End

func (t *RangeKey) End() Key

func (*RangeKey) EndExtent

func (t *RangeKey) EndExtent() Key

func (*RangeKey) EndInclusive

func (t *RangeKey) EndInclusive() bool

func (*RangeKey) Equals

func (t *RangeKey) Equals(elem any) bool

func (*RangeKey) Less

func (t *RangeKey) Less(elem interface{}) bool

func (*RangeKey) LessOrEquals

func (t *RangeKey) LessOrEquals(elem interface{}) bool

func (*RangeKey) SetEndExtent

func (t *RangeKey) SetEndExtent(key Key)

func (*RangeKey) SetStartExtent

func (t *RangeKey) SetStartExtent(key Key)

func (*RangeKey) Start

func (t *RangeKey) Start() Key

func (*RangeKey) StartExtent

func (t *RangeKey) StartExtent() Key

func (*RangeKey) StartInclusive

func (t *RangeKey) StartInclusive() bool

func (*RangeKey) String

func (t *RangeKey) String() string

type SchedEvent

type SchedEvent interface {
	SetJob(job func())
	Job() func()
	Run(ctx context.Context, node Node) error
	ProcessRequest(ctx context.Context, node Node) SchedEvent
	SetCanceled(c bool)
	IsCanceled() bool
	Event
}

type StringKey

type StringKey string

func (StringKey) Encode

func (t StringKey) Encode() *pb.Key

func (StringKey) Equals

func (t StringKey) Equals(elem any) bool

func (StringKey) Less

func (t StringKey) Less(elem interface{}) bool

func (StringKey) LessOrEquals

func (t StringKey) LessOrEquals(elem interface{}) bool

func (StringKey) String

func (t StringKey) String() string

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

Directories

Path Synopsis
p2p
pb

Jump to

Keyboard shortcuts

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