graph

package
v0.0.0-...-ff61ee7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIndicesID

func GetIndicesID(ev []*Event, n int) [][]int

GetIndicesID returns the indices of the events per id

Types

type Event

type Event struct {
	EventInfo
	MyHash types.HashBytes

	WI *witnessInfo // non-nil if this Event is a witness, nil otherwise
	// contains filtered or unexported fields
}

func (*Event) GetRound

func (ev *Event) GetRound() IndexType

type EventInfo

type EventInfo struct {
	LocalInfo       EventPointer   // Local id and index, plus hash of local ancestor
	RemoteAncestors []EventPointer // Remote ancestors
	Buff            []byte         // proposal
}

func (*EventInfo) Decode

func (ev *EventInfo) Decode(reader io.Reader) (n int, err error)

func (*EventInfo) Encode

func (ev *EventInfo) Encode(writer io.Writer) (n int, err error)

type EventPointer

type EventPointer struct {
	ID, Index IndexType
	Hash      types.HashBytes
}

func (*EventPointer) Decode

func (ac *EventPointer) Decode(reader io.Reader) (n int, err error)

func (*EventPointer) Encode

func (ac *EventPointer) Encode(writer io.Writer) (n int, err error)

type Graph

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

func InitGraph

func InitGraph(nodeCount, nmt int, initHash types.HashBytes) *Graph

InitGraph creates a Graph with n nodes each with an initial Event at Index 0

func (*Graph) AddEvent

func (g *Graph) AddEvent(ev EventInfo, checkOnly bool) (event *Event, err error)

AddEvent adds the Event to the Graph and returns an error if the Event in invalid. It returns the Event added.

func (*Graph) AddEvents

func (g *Graph) AddEvents(events []EventInfo) (added []*Event, remainder, invalid []EventInfo)

AddEvents adds a set of events to the Graph. added are the events that we successfully added remainder are the ones that were not able to be added because their ancestors have not yet been added. invalid are those that created errors when adding.

func (*Graph) CheckGCIndex

func (g *Graph) CheckGCIndex(index IndexType, gcFunc func(*Event) bool)

CheckGCIndex will check for garbage collection of events happening at index index and before.

func (*Graph) ComputeDiffID

func (g *Graph) ComputeDiffID(id IndexType) (ret []*Event)

ComputeDiffID returns the events to which there is no path from the most recent Event of ID from. (this is used to send values to a different node when creating a new Event)

func (*Graph) ComputeDiffIDIndex

func (g *Graph) ComputeDiffIDIndex(id IndexType) (ret []IndexType)

ComputeDiffID returns the index of the events to which there is no path from the most recent Event of ID from. (this is used to send values to a different node when creating a new Event)

func (*Graph) ContainsEventPointer

func (g *Graph) ContainsEventPointer(ev EventPointer) bool

containsEventPointer returns true if the event pointer is contained in the graph

func (*Graph) CreateEvent

func (g *Graph) CreateEvent(localID, remoteID IndexType, buff []byte, checkOnly bool) *Event

CreateEvent creates a new Event from the local node ID to the remote node ID with the Buff as its proposal

func (*Graph) CreateEventIndex

func (g *Graph) CreateEventIndex(localID IndexType, buff []byte, checkOnly bool) *Event

CreateEventIndex creates an event at localID. All other ids that have the same index as (or larger than) the current localID index will be added as remote dependencies.

func (*Graph) GetDecision

func (g *Graph) GetDecision(round IndexType) (hasDecided bool, decision [][][]byte, decisionRounds []IndexType,
	decisionIndex []IndexType, decCount int, decisionBools []bool)

GetDecision returns true if the round has decided. It returns the set of n decided values (a voted no decision will have a nil value), and the rounds that caused each of the n events to decide. decCount is the number of nodes that decided yes for the index.

func (*Graph) GetDecisionEvents

func (g *Graph) GetDecisionEvents(r IndexType) (ret []*Event, err error)

GetDecisionEvents returns the set of events that caused round r to decide that follow those that caused round r+1 to decide. If called on a round not yet decided it returns the events after the most recent decision.

func (*Graph) GetIndices

func (g *Graph) GetIndices() []IndexType

GetIndices returns the current indices of each node id.

func (*Graph) GetLargerIndexCount

func (g *Graph) GetLargerIndexCount(localID IndexType) (count int)

GetLarger index count returns the number of IDs that have events with index as large or larger than the index of the event at ID localID (including the event at localID).

func (*Graph) GetMissingDependencies

func (g *Graph) GetMissingDependencies(ev EventInfo) (ret []EventPointer)

getMissingDependencies returns the ancestors that of ev that are not in the graph.

func (*Graph) GetMissingEvents

func (g *Graph) GetMissingEvents(ev *Event, indices []IndexType) (maxIdxs []IndexType, ret []*Event)

GetMissingEvents returns the events that are needed by ev, but not contained in indices, maxIds is the maximum id of the indices at each index.

func (*Graph) GetMoreRecent

func (g *Graph) GetMoreRecent(indices []IndexType) (ret []*Event, gcIdxs []IndexType, err error)

GetMoreRecent takes a list of indices, one per node id and returns the events that follow. If any indices have been garbage collected and have events that are needed then the indices are returned as part of gcIdxs.

func (*Graph) GetWitnesses

func (g *Graph) GetWitnesses(idx IndexType) [][]*Event

GetWitnesses returns the set of witnesses for the given index.

type IndexType

type IndexType int32

func GetIndices

func GetIndices(ev []*Event) []IndexType

GetIndices returns the indices of the events.

func MaxIndices

func MaxIndices(items ...[]IndexType) []IndexType

MaxIndices returns the max at each index of the inputs.

type SortEvent

type SortEvent []EventInfo

func (SortEvent) Len

func (l SortEvent) Len() int

func (SortEvent) Less

func (l SortEvent) Less(i, j int) bool

func (SortEvent) Swap

func (l SortEvent) Swap(i, j int)

Jump to

Keyboard shortcuts

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