dataStructures

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 25 Imported by: 12

Documentation

Overview

Package dataStructures stores callbacks that will be called in the process of running a round.

Index

Constants

View Source
const RoundInfoBufLen = 1500
View Source
const RoundUpdatesBufLen = 1500

Variables

This section is empty.

Functions

func GenerateNDFHash

func GenerateNDFHash(msg *pb.NDF) ([]byte, error)

GenerateNDFHash generates a hash of the unmarshalled NDF bytes in the comms message. If the message or NDF bytes is nil, zeroes are returned.

Types

type Circuit

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

func NewCircuit

func NewCircuit(list []*id.ID) *Circuit

New makes a list of node addresses for use. It finds the passed "myId" and denotes it internally for use with utility functions. The nodeID are copied instead of linked to ensure any modification of them does not change the Circuit structure. Will panic if the length of the passed list is zero.

func (*Circuit) AddHost

func (c *Circuit) AddHost(newHost *connect.Host)

SetHosts takes a list of hosts and copies them into the list of hosts in the circuit object

func (*Circuit) GetHostAtIndex

func (c *Circuit) GetHostAtIndex(index int) *connect.Host

GetHostAtIndex: Gets host at requested index. Panics if index is outside of the range of the list

func (*Circuit) GetLastNode

func (c *Circuit) GetLastNode() *id.ID

Get the last node in the circuit, will panic if the circuit has nil as a node

func (*Circuit) GetNextNode

func (c *Circuit) GetNextNode(from *id.ID) *id.ID

GetNextNode gets the node following the passed node in the list. It wraps around to the beginning of the list if the passed node is the last node.

func (*Circuit) GetNodeAtIndex

func (c *Circuit) GetNodeAtIndex(index int) *id.ID

GetNodeAtIndex returns the node at the given index. Panics if the index does not exist within the circuit

func (*Circuit) GetNodeLocation

func (c *Circuit) GetNodeLocation(node *id.ID) int

GetNodeLocation returns the location of the passed node in the list. Returns -1 if the node is not in the list

func (*Circuit) GetOrdering

func (c *Circuit) GetOrdering() []*Circuit

GetOrdering returns a slice of Circuits with each one having a different shifted ordering.

func (*Circuit) GetPrevNode

func (c *Circuit) GetPrevNode(from *id.ID) *id.ID

GetNextNode gets the node preceding the passed node in the list. It wraps around to the end of the list if the passed node is the first node.

func (*Circuit) IsFirstNode

func (c *Circuit) IsFirstNode(node *id.ID) bool

IsFirstNode returns true if the passed node is the first node, false otherwise

func (*Circuit) IsLastNode

func (c *Circuit) IsLastNode(node *id.ID) bool

IsLastNode returns true if the passed node is the last node, false otherwise

func (*Circuit) Len

func (c *Circuit) Len() int

Len returns the number of nodes in the circuit

type Data

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

ID numbers can overwrite

func NewData

func NewData() *Data

Initialize a new Data object

func (*Data) GetLastRoundID

func (d *Data) GetLastRoundID() id.Round

Get the ID of the newest round in the buffer

func (*Data) GetOldestRoundID

func (d *Data) GetOldestRoundID() id.Round

Gets the ID of the oldest roundd in the buffer

func (*Data) GetRound

func (d *Data) GetRound(id int) (*mixmessages.RoundInfo, error)

Get a given round id from the ring buffer as a roundInfo

func (*Data) GetWrappedRound

func (d *Data) GetWrappedRound(id int) (*Round, error)

Get a given round id from the ring buffer as a round object

func (*Data) UpsertRound

func (d *Data) UpsertRound(r *Round) error

Upsert a round into the ring bugger

type EventCallback

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

EventCallback contains one callback and associated data.

type EventReturn

type EventReturn struct {
	RoundInfo *pb.RoundInfo
	TimedOut  bool
}

type ExternalRoundStorage

type ExternalRoundStorage interface {
	// Store: stores the round info inside the underlying storage medium, which generally is a database. Store will
	// add the round info to the database if it doesn't exist and will only overwrite the data if it does exist in the
	// event that the update ID of the passed in data is greater than the update ID of the existing round info.
	Store(*pb.RoundInfo) error
	// Retrieve will return the round info for the given round ID and will return nil but not an error if it does not
	// exist.
	Retrieve(id id.Round) (*pb.RoundInfo, error)
	// RetrieveMany will return all rounds passed in in the ID list, if the round doesn't its reciprocal entry in the
	// returned slice will be blank.
	RetrieveMany(rounds []id.Round) ([]*pb.RoundInfo, error)
	// RetrieveRange will return all rounds in the range, if the round doesn't exist the reciprocal entry in the
	// returned slice will be blank.
	RetrieveRange(first, last id.Round) ([]*pb.RoundInfo, error)
}

The ExtendedRoundStorage (ERS) interface allows storing rounds inside of an external database for clients to pull from, because the ring buffer only contains a limited number of them while clients might need to go further back into history.

type Group

type Group struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

Struct that handles and updates cyclic.Groups

func NewGroup

func NewGroup() *Group

NewGroup creates a ds.Group with a cyclic.Group and a mutex

func (*Group) Get

func (g *Group) Get() *cyclic.Group

Get returns the ds.Groups's cyclic group

func (*Group) GetString

func (g *Group) GetString() string

Get returns the ds.Groups's cyclic group string

func (*Group) Update

func (g *Group) Update(newGroup string) error

Update sets the group's string and cyclic.Group object If these values have not been set yet, we set these two values If these values are set and the newGroup is different, it errors

as the group should be immutable after being set

func (Group) UpdateCyclicGroupTesting

func (g Group) UpdateCyclicGroupTesting(group *cyclic.Group, i interface{})

Utility function for NewInstanceTesting that directly sets cyclic.Group object USED FOR TESTING PURPOSED ONLY

type IpOverrideList

type IpOverrideList struct {
	sync.Mutex
	// contains filtered or unexported fields
}

structure which holds a list of IP address to override

func NewIpOverrideList

func NewIpOverrideList() *IpOverrideList

creates a new list over IP overrides

func (*IpOverrideList) CheckOverride

func (iol *IpOverrideList) CheckOverride(cid *id.ID, ip string) string

checks if an ip should be overwritten. returns the passed IP if it should not be overwritten

func (*IpOverrideList) Override

func (iol *IpOverrideList) Override(oid *id.ID, ip string)

sets an id to be overridden with a specific IP address

type Ndf

type Ndf struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Ndf encapsulates all data from an NDF.

func NewNdf

func NewNdf(definition *ndf.NetworkDefinition) (*Ndf, error)

NewNdf initializes a Ndf object from a primitives ndf.NetworkDefinition.

func (*Ndf) CompareHash

func (file *Ndf) CompareHash(h []byte) bool

CompareHash evaluates if the passed NDF hash is the same as the stored one.

func (*Ndf) Get

func (file *Ndf) Get() *ndf.NetworkDefinition

Get returns the NDF object. FIXME: return a copy instead to ensure edits to not impact the original version

func (*Ndf) GetHash

func (file *Ndf) GetHash() []byte

GetHash returns the NDF hash.

func (*Ndf) GetPb

func (file *Ndf) GetPb() *pb.NDF

GetPb returns the NDF message. FIXME: return a copy instead to ensure edits to not impact the original version

func (*Ndf) Update

func (file *Ndf) Update(m *pb.NDF) error

Update to a new NDF if the passed NDF is valid.

type Round

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

Structure wraps a round info object with the key to verify the protobuff's signature and a state track for verifying

func NewRound

func NewRound(ri *pb.RoundInfo, rsaPubKey *rsa.PublicKey, ecPubKey *ec.PublicKey) *Round

Constructor of a Round object.

func NewVerifiedRound

func NewVerifiedRound(ri *pb.RoundInfo, pubkey *rsa.PublicKey) *Round

Constructor of an already verified round object Intended for use by round creator.

func (*Round) Get

func (r *Round) Get() *pb.RoundInfo

Get returns the round info object. If we have not validated the signature before, we then verify. Later calls will not need validation

func (*Round) StartTime

func (r *Round) StartTime() time.Time

type RoundEventCallback

type RoundEventCallback func(ri *pb.RoundInfo, timedOut bool)

RoundEventCallback is the callbacks called on trigger.

type RoundEvents

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

RoundEvents holds the callbacks for a round.

func NewRoundEvents

func NewRoundEvents() *RoundEvents

NewRoundEvents initialize a new RoundEvents object.

func (*RoundEvents) AddRoundEvent

func (r *RoundEvents) AddRoundEvent(rid id.Round, callback RoundEventCallback,
	timeout time.Duration, validStates ...states.Round) *EventCallback

AddRoundEvent adds an event to the RoundEvents struct and returns its handle for possible deletion.

func (*RoundEvents) AddRoundEventChan

func (r *RoundEvents) AddRoundEventChan(rid id.Round,
	eventChan chan EventReturn, timeout time.Duration,
	validStates ...states.Round) *EventCallback

AddRoundEventChan puts the round event on a channel instead of using a callback.

func (*RoundEvents) Remove

func (r *RoundEvents) Remove(rid id.Round, e *EventCallback)

Remove wraps non-exported remove with mutex.

func (*RoundEvents) TriggerRoundEvent

func (r *RoundEvents) TriggerRoundEvent(rnd *Round)

TriggerRoundEvent signals all round events matching the passed RoundInfo according to its ID and state.

func (*RoundEvents) TriggerRoundEvents

func (r *RoundEvents) TriggerRoundEvents(rounds ...*Round)

TriggerRoundEvents signals all round events matching the passed RoundInfos according to its ID and state.

type Updates

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

Standard ring buffer, but objects come with numbering

func NewUpdates

func NewUpdates() *Updates

Create a new Updates object

func (*Updates) AddRound

func (u *Updates) AddRound(rnd *Round) error

Add a round to the ring buffer

func (*Updates) GetLastUpdateID

func (u *Updates) GetLastUpdateID() int

Get the id of the newest update in the buffer

func (*Updates) GetUpdate

func (u *Updates) GetUpdate(id int) (*pb.RoundInfo, error)

Get a given update ID from the ring buffer

func (*Updates) GetUpdates

func (u *Updates) GetUpdates(id int) []*pb.RoundInfo

gets all updates after a given ID

type WaitingRounds

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

WaitingRounds contains a list of all queued rounds ordered by which occurs furthest in the future with the furthest in the back.

func NewWaitingRounds

func NewWaitingRounds() *WaitingRounds

NewWaitingRounds generates a new WaitingRounds with an empty round list.

func (*WaitingRounds) GetSlice

func (wr *WaitingRounds) GetSlice() []*pb.RoundInfo

GetSlice returns a slice of all round infos in the list that have yet to occur.

func (*WaitingRounds) GetUpcomingRealtime

func (wr *WaitingRounds) GetUpcomingRealtime(timeout time.Duration,
	exclude excludedRounds.ExcludedRounds, numAttempts int, minRoundAge time.Duration) (*pb.RoundInfo, time.Duration, error)

GetUpcomingRealtime returns the round that will occur furthest in the future. If the list is empty, then it waits for a round to be added for the specified duration. If no round is added, then an error is returned.

The length of the excluded set indicates how many times the client has called GetUpcomingRealtime trying to retrieve a round to send on. GetUpcomingRealtime defaults to retrieving the closest non-excluded round from WaitingRounds. If the length of the excluded set exceeds the maximum attempts at pulling the closest round, GetUpcomingRealtime will retrieve the furthest non-excluded round from WaitingRounds.

func (*WaitingRounds) HasValidRounds

func (wr *WaitingRounds) HasValidRounds(now time.Time) bool

HasValidRounds returns true if there is at least one valid round in the queue according to its timestamp. This means they are in the "QUEUED" state and their start time is after the local time

func (*WaitingRounds) Insert

func (wr *WaitingRounds) Insert(added, removed []*Round)

Insert inserts a queued round into the list in order of its timestamp, from smallest to greatest. If the new round is not in a QUEUED state, then it is not inserted. If the new round already exists in the list but is no longer queued, then it is removed.

func (*WaitingRounds) Len

func (wr *WaitingRounds) Len() int

Len returns the number of rounds in the list.

func (*WaitingRounds) NumValidRounds

func (wr *WaitingRounds) NumValidRounds(now time.Time) int

NumValidRounds returns how many rounds are, according to the local timestamp, ready to be sent to. This means they are in the "QUEUED" state and their start time is after the local time

Jump to

Keyboard shortcuts

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