Documentation ¶
Index ¶
- Constants
- Variables
- type AccessManaCache
- type BufferQueue
- func (b *BufferQueue) Current() *NodeQueue
- func (b *BufferQueue) IDs() (ids []ElementID)
- func (b *BufferQueue) InsertNode(nodeID identity.ID)
- func (b *BufferQueue) MaxSize() int
- func (b *BufferQueue) Next() *NodeQueue
- func (b *BufferQueue) NodeIDs() []identity.ID
- func (b *BufferQueue) NodeQueue(nodeID identity.ID) *NodeQueue
- func (b *BufferQueue) NumActiveNodes() int
- func (b *BufferQueue) PopFront() Element
- func (b *BufferQueue) Ready(blk Element) bool
- func (b *BufferQueue) ReadyBlocksCount() (readyBlkCount int)
- func (b *BufferQueue) RemoveNode(nodeID identity.ID)
- func (b *BufferQueue) Size() int
- func (b *BufferQueue) Submit(blk Element, accessManaRetriever func(identity.ID) float64) (elements []ElementID, err error)
- func (b *BufferQueue) TotalBlocksCount() (blkCount int)
- func (b *BufferQueue) Unsubmit(blk Element) bool
- type Element
- type ElementHeap
- type ElementID
- type NodeQueue
- func (q *NodeQueue) Front() Element
- func (q *NodeQueue) IDs() (ids []ElementID)
- func (q *NodeQueue) NodeID() identity.ID
- func (q *NodeQueue) PopFront() Element
- func (q *NodeQueue) Ready(element Element) bool
- func (q *NodeQueue) Size() int
- func (q *NodeQueue) Submit(element Element) bool
- func (q *NodeQueue) Unsubmit(element Element) bool
Constants ¶
const ElementIDLength = 32
ElementIDLength defines the length of an ElementID.
Variables ¶
var ErrInsufficientMana = errors.New("insufficient node's mana to schedule the block")
ErrInsufficientMana is returned when the mana is insufficient.
Functions ¶
This section is empty.
Types ¶
type AccessManaCache ¶ added in v0.8.4
type AccessManaCache struct {
// contains filtered or unexported fields
}
AccessManaCache is a structure which provides access to cached access mana values. Mana values are refreshed after certain amount of time has passed.
func NewAccessManaCache ¶ added in v0.8.4
func NewAccessManaCache(accessManaMapRetrieverFunc func() map[identity.ID]float64, totalAccessManaRetrieverFunc func() float64, minMana float64) *AccessManaCache
NewAccessManaCache returns a new AccessManaCache.
func (*AccessManaCache) GetCachedMana ¶ added in v0.8.4
func (a *AccessManaCache) GetCachedMana(id identity.ID) float64
GetCachedMana returns cached access mana value for a given node and refreshes mana vectors if they expired currently returns at least MinMana.
func (*AccessManaCache) GetCachedTotalMana ¶ added in v0.9.1
func (a *AccessManaCache) GetCachedTotalMana() float64
GetCachedTotalMana returns cached total mana value.
func (*AccessManaCache) RawAccessManaVector ¶ added in v0.8.4
func (a *AccessManaCache) RawAccessManaVector() map[identity.ID]float64
RawAccessManaVector returns raw access mana vector retrieved from mana plugin.
func (*AccessManaCache) RefreshCacheIfNecessary ¶ added in v0.9.1
func (a *AccessManaCache) RefreshCacheIfNecessary()
RefreshCacheIfNecessary refreshes mana cache after it has expired.
type BufferQueue ¶
type BufferQueue struct {
// contains filtered or unexported fields
}
BufferQueue represents a buffer of NodeQueue.
func NewBufferQueue ¶
func NewBufferQueue(maxBuffer int, maxQueue float64) *BufferQueue
NewBufferQueue returns a new BufferQueue.
func (*BufferQueue) Current ¶
func (b *BufferQueue) Current() *NodeQueue
Current returns the current NodeQueue in round robin order.
func (*BufferQueue) IDs ¶
func (b *BufferQueue) IDs() (ids []ElementID)
IDs returns the IDs of all submitted blocks (ready or not).
func (*BufferQueue) InsertNode ¶ added in v0.8.4
func (b *BufferQueue) InsertNode(nodeID identity.ID)
InsertNode creates a queue for the given node and adds it to the list of active nodes.
func (*BufferQueue) MaxSize ¶ added in v0.8.4
func (b *BufferQueue) MaxSize() int
MaxSize returns the max size (in bytes) of all blocks in b.
func (*BufferQueue) Next ¶
func (b *BufferQueue) Next() *NodeQueue
Next returns the next NodeQueue in round robin order.
func (*BufferQueue) NodeIDs ¶
func (b *BufferQueue) NodeIDs() []identity.ID
NodeIDs returns the nodeIDs of all nodes.
func (*BufferQueue) NodeQueue ¶
func (b *BufferQueue) NodeQueue(nodeID identity.ID) *NodeQueue
NodeQueue returns the queue for the corresponding node.
func (*BufferQueue) NumActiveNodes ¶
func (b *BufferQueue) NumActiveNodes() int
NumActiveNodes returns the number of active nodes in b.
func (*BufferQueue) PopFront ¶
func (b *BufferQueue) PopFront() Element
PopFront removes the first ready block from the queue of the current node.
func (*BufferQueue) Ready ¶
func (b *BufferQueue) Ready(blk Element) bool
Ready marks a previously submitted block as ready to be scheduled.
func (*BufferQueue) ReadyBlocksCount ¶ added in v0.9.2
func (b *BufferQueue) ReadyBlocksCount() (readyBlkCount int)
ReadyBlocksCount returns the number of ready blocks in the buffer.
func (*BufferQueue) RemoveNode ¶
func (b *BufferQueue) RemoveNode(nodeID identity.ID)
RemoveNode removes all blocks (submitted and ready) for the given node.
func (*BufferQueue) Size ¶
func (b *BufferQueue) Size() int
Size returns the total size (in bytes) of all blocks in b.
func (*BufferQueue) Submit ¶
func (b *BufferQueue) Submit(blk Element, accessManaRetriever func(identity.ID) float64) (elements []ElementID, err error)
Submit submits a block. Return blocks dropped from the scheduler to make room for the submitted block. The submitted block can also be returned as dropped if the issuing node does not have enough access mana.
func (*BufferQueue) TotalBlocksCount ¶ added in v0.9.2
func (b *BufferQueue) TotalBlocksCount() (blkCount int)
TotalBlocksCount returns the number of blocks in the buffer.
func (*BufferQueue) Unsubmit ¶
func (b *BufferQueue) Unsubmit(blk Element) bool
Unsubmit removes a block from the submitted blocks. If that block is already marked as ready, Unsubmit has no effect.
type Element ¶
type Element interface { // IDBytes returns the ID of an Element as a byte slice. IDBytes() []byte // Size returns the size of the element. Size() int // IssuerPublicKey returns the issuer public key of the element. IssuerPublicKey() ed25519.PublicKey // IssuingTime returns the issuing time of the block. IssuingTime() time.Time }
Element represents the generic interface for an block in NodeQueue.
type ElementHeap ¶
type ElementHeap []Element
ElementHeap holds a heap of blocks with respect to their IssuingTime.
func (ElementHeap) Len ¶
func (h ElementHeap) Len() int
Len is the number of elements in the collection.
func (ElementHeap) Less ¶
func (h ElementHeap) Less(i, j int) bool
Less reports whether the element with index i must sort before the element with index j.
func (*ElementHeap) Pop ¶
func (h *ElementHeap) Pop() interface{}
Pop removes and returns element with index Len() - 1.
func (*ElementHeap) Push ¶
func (h *ElementHeap) Push(x interface{})
Push adds x as element with index Len(). It panics if x is not Element.
func (ElementHeap) Swap ¶
func (h ElementHeap) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type ElementID ¶
type ElementID [ElementIDLength]byte
ElementID defines the ID of element.
func ElementIDFromBytes ¶
ElementIDFromBytes converts byte array to an ElementID.
type NodeQueue ¶
type NodeQueue struct {
// contains filtered or unexported fields
}
NodeQueue keeps the submitted blocks of a node.
func NewNodeQueue ¶
NewNodeQueue returns a new NodeQueue.
func (*NodeQueue) Size ¶
Size returns the total size of the blocks in the queue. This function is thread-safe.