Documentation
¶
Overview ¶
Package dataStructures stores callbacks that will be called in the process of running a round.
Index ¶
- Constants
- func GenerateNDFHash(msg *pb.NDF) ([]byte, error)
- type Circuit
- func (c *Circuit) AddHost(newHost *connect.Host)
- func (c *Circuit) GetHostAtIndex(index int) *connect.Host
- func (c *Circuit) GetLastNode() *id.ID
- func (c *Circuit) GetNextNode(from *id.ID) *id.ID
- func (c *Circuit) GetNodeAtIndex(index int) *id.ID
- func (c *Circuit) GetNodeLocation(node *id.ID) int
- func (c *Circuit) GetOrdering() []*Circuit
- func (c *Circuit) GetPrevNode(from *id.ID) *id.ID
- func (c *Circuit) IsFirstNode(node *id.ID) bool
- func (c *Circuit) IsLastNode(node *id.ID) bool
- func (c *Circuit) Len() int
- type Data
- type EventCallback
- type EventReturn
- type ExternalRoundStorage
- type Group
- type IpOverrideList
- type Ndf
- type Round
- type RoundEventCallback
- type RoundEvents
- func (r *RoundEvents) AddRoundEvent(rid id.Round, callback RoundEventCallback, timeout time.Duration, ...) *EventCallback
- func (r *RoundEvents) AddRoundEventChan(rid id.Round, eventChan chan EventReturn, timeout time.Duration, ...) *EventCallback
- func (r *RoundEvents) Remove(rid id.Round, e *EventCallback)
- func (r *RoundEvents) TriggerRoundEvent(rnd *Round)
- func (r *RoundEvents) TriggerRoundEvents(rounds ...*Round)
- type Updates
- type WaitingRounds
- func (wr *WaitingRounds) GetSlice() []*pb.RoundInfo
- func (wr *WaitingRounds) GetUpcomingRealtime(timeout time.Duration, exclude excludedRounds.ExcludedRounds, numAttempts int, ...) (*pb.RoundInfo, time.Duration, error)
- func (wr *WaitingRounds) HasValidRounds(now time.Time) bool
- func (wr *WaitingRounds) Insert(added, removed []*Round)
- func (wr *WaitingRounds) Len() int
- func (wr *WaitingRounds) NumValidRounds(now time.Time) int
Constants ¶
const RoundInfoBufLen = 1500
const RoundUpdatesBufLen = 1500
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Circuit ¶
type Circuit struct {
// contains filtered or unexported fields
}
func NewCircuit ¶
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 ¶
SetHosts takes a list of hosts and copies them into the list of hosts in the circuit object
func (*Circuit) GetHostAtIndex ¶
GetHostAtIndex: Gets host at requested index. Panics if index is outside of the range of the list
func (*Circuit) GetLastNode ¶
Get the last node in the circuit, will panic if the circuit has nil as a node
func (*Circuit) GetNextNode ¶
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 ¶
GetNodeAtIndex returns the node at the given index. Panics if the index does not exist within the circuit
func (*Circuit) GetNodeLocation ¶
GetNodeLocation returns the location of the passed node in the list. Returns -1 if the node is not in the list
func (*Circuit) GetOrdering ¶
GetOrdering returns a slice of Circuits with each one having a different shifted ordering.
func (*Circuit) GetPrevNode ¶
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 ¶
IsFirstNode returns true if the passed node is the first node, false otherwise
func (*Circuit) IsLastNode ¶
IsLastNode returns true if the passed node is the last node, false otherwise
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
ID numbers can overwrite
func (*Data) GetLastRoundID ¶
Get the ID of the newest round in the buffer
func (*Data) GetOldestRoundID ¶
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 ¶
Get a given round id from the ring buffer as a round object
func (*Data) UpsertRound ¶
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 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 ¶
Struct that handles and updates cyclic.Groups
func (*Group) Update ¶
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 ¶
Utility function for NewInstanceTesting that directly sets cyclic.Group object USED FOR TESTING PURPOSED ONLY
type IpOverrideList ¶
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
type Ndf ¶
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 ¶
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
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 NewVerifiedRound ¶
Constructor of an already verified round object Intended for use by round creator.
type RoundEventCallback ¶
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 (*Updates) GetLastUpdateID ¶
Get the id of the newest update in the buffer
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