algo

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefDigestWaitTime   = 1000 * time.Millisecond
	DefRequestWaitTime  = 1500 * time.Millisecond
	DefResponseWaitTime = 2000 * time.Millisecond
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DigestFilter

type DigestFilter func(context interface{}) func(digestItem string) bool

DigestFilter filters digests to be sent to a remote peer that sent a hello or a request, based on its messages's context

type PullAdapter

type PullAdapter interface {
	// SelectPeers returns a slice of peers which the engine will initiate the protocol with
	SelectPeers() []string

	// Hello sends a hello message to initiate the protocol
	// and returns an NONCE that is expected to be returned
	// in the digest message.
	Hello(dest string, nonce uint64)

	// SendDigest sends a digest to a remote PullEngine.
	// The context parameter specifies the remote engine to send to.
	SendDigest(digest []string, nonce uint64, context interface{})

	// SendReq sends an array of items to a certain remote PullEngine identified
	// by a string
	SendReq(dest string, items []string, nonce uint64)

	// SendRes sends an array of items to a remote PullEngine identified by a context.
	SendRes(items []string, context interface{}, nonce uint64)
}

PullAdapter is needed by the PullEngine in order to send messages to the remote PullEngine instances. The PullEngine expects to be invoked with OnHello, OnDigest, OnReq, OnRes when the respective message arrives from a remote PullEngine

type PullEngine

type PullEngine struct {
	PullAdapter
	// contains filtered or unexported fields
}

PullEngine is the component that actually invokes the pull algorithm with the help of the PullAdapter

func NewPullEngine

func NewPullEngine(participant PullAdapter, sleepTime time.Duration, config PullEngineConfig) *PullEngine

NewPullEngine creates an instance of a PullEngine with a certain sleep time between pull initiations

func NewPullEngineWithFilter

func NewPullEngineWithFilter(participant PullAdapter, sleepTime time.Duration, df DigestFilter,
	config PullEngineConfig) *PullEngine

NewPullEngineWithFilter creates an instance of a PullEngine with a certain sleep time between pull initiations, and uses the given filters when sending digests and responses

func (*PullEngine) Add

func (engine *PullEngine) Add(seqs ...string)

Add adds items to the state

func (*PullEngine) OnDigest

func (engine *PullEngine) OnDigest(digest []string, nonce uint64, context interface{})

OnDigest notifies the engine that a digest has arrived

func (*PullEngine) OnHello

func (engine *PullEngine) OnHello(nonce uint64, context interface{})

OnHello notifies the engine a hello has arrived

func (*PullEngine) OnReq

func (engine *PullEngine) OnReq(items []string, nonce uint64, context interface{})

OnReq notifies the engine a request has arrived

func (*PullEngine) OnRes

func (engine *PullEngine) OnRes(items []string, nonce uint64)

OnRes notifies the engine a response has arrived

func (*PullEngine) Remove

func (engine *PullEngine) Remove(seqs ...string)

Remove removes items from the state

func (*PullEngine) Stop

func (engine *PullEngine) Stop()

Stop stops the engine

type PullEngineConfig

type PullEngineConfig struct {
	DigestWaitTime   time.Duration
	RequestWaitTime  time.Duration
	ResponseWaitTime time.Duration
}

PullEngineConfig is the configuration required to initialize a new pull engine

Jump to

Keyboard shortcuts

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