algo

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDigestWaitTime

func SetDigestWaitTime(time time.Duration)

SetDigestWaitTime sets the digest wait time

func SetRequestWaitTime

func SetRequestWaitTime(time time.Duration)

SetRequestWaitTime sets the request wait time

func SetResponseWaitTime

func SetResponseWaitTime(time time.Duration)

SetResponseWaitTime sets the response wait time

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) *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) *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

Jump to

Keyboard shortcuts

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