scuttlebutt

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(update *Update, sources Sources) bool

func Sort

func Sort(history []*Update)

Types

type CreateIdFn

type CreateIdFn func() SourceId

type IsAccepted

type IsAccepted func(update *Update) bool

type Model added in v1.1.1

type Model interface {
	IsAccepted(peerAccept *ModelAccept, update *Update) bool
	// 更新己方消息
	ApplyUpdates(update *Update) bool
	// 根据对端传来的 clock,计算出来的 delta。而 delta 是 Update 集合
	// 每个 stream 上记录对端传来的 clock,并且会随着后续从 stream 收到的 Update 不断更新
	History(peerSources Sources, accept *ModelAccept) []*Update
}

type ModelAccept

type ModelAccept struct {
	Whitelist []string `json:"whitelist"`
	Blacklist []string `json:"blacklist"`
}

type ModelValueItems added in v1.1.1

type ModelValueItems int
const (
	ModelValueItemsKey ModelValueItems = iota
	ModelValueItemsValue
)

type Option

type Option func(*Scuttlebutt)

func WithAccept added in v1.0.1

func WithAccept(accept *ModelAccept) Option

func WithId

func WithId(id SourceId) Option

type Scuttlebutt

type Scuttlebutt struct {
	Model
	*event.Emitter

	Accept  *ModelAccept
	Sources Sources

	Streams int
	// contains filtered or unexported fields
}

func NewScuttlebutt

func NewScuttlebutt(model Model, opts ...Option) *Scuttlebutt

func (*Scuttlebutt) ApplyUpdates

func (sb *Scuttlebutt) ApplyUpdates(update *Update) bool

func (*Scuttlebutt) Dispose added in v1.0.1

func (sb *Scuttlebutt) Dispose()

each stream will be ended due to this event

func (*Scuttlebutt) History

func (sb *Scuttlebutt) History(peerSources Sources, accept *ModelAccept) []*Update

func (*Scuttlebutt) Id

func (sb *Scuttlebutt) Id() SourceId

func (*Scuttlebutt) IsAccepted

func (sb *Scuttlebutt) IsAccepted(peerAccept *ModelAccept, update *Update) bool

func (*Scuttlebutt) LocalUpdate

func (sb *Scuttlebutt) LocalUpdate(any [2]interface{})

func (*Scuttlebutt) Update

func (sb *Scuttlebutt) Update(update *Update) bool

type Sign

type Sign func(update *Update) (string, error)

type SourceId

type SourceId string

全局唯一

func CreateId

func CreateId() SourceId

type Sources

type Sources map[SourceId]Timestamp

"我"所知道的所有和“我”相连的节点(包括我自己的)的最新时间戳 会随着后续所有 stream 上收到的 Update 来更新

type Timestamp

type Timestamp int64

type Update

type Update struct {
	Data      [2]interface{} `json:"data"`
	Timestamp Timestamp      `json:"timestamp"`
	SourceId  SourceId       `json:"source_id"`
	From      SourceId       `json:"from"`
	Digest    string         `json:"digest"`
}

一次更新

type Verify

type Verify func(update *Update) bool

Jump to

Keyboard shortcuts

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