scuttlebutt

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 10 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 Accept added in v1.1.0

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

type CreateIdFn

type CreateIdFn func() SourceId

type IsAccepted

type IsAccepted func(update *Update) bool

type Option

type Option func(*Scuttlebutt)

func WithAccept added in v1.0.1

func WithAccept(accept *Accept) Option

func WithId

func WithId(id SourceId) Option

type Protocol

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

type Scuttlebutt

type Scuttlebutt struct {
	Protocol
	*event.Emitter

	Accept  *Accept
	Sources Sources

	Streams int
	// contains filtered or unexported fields
}

func NewScuttlebutt

func NewScuttlebutt(protocol Protocol, 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 interface{}) []*Update

func (*Scuttlebutt) Id

func (sb *Scuttlebutt) Id() SourceId

func (*Scuttlebutt) IsAccepted

func (sb *Scuttlebutt) IsAccepted(peerAccept interface{}, update *Update) bool

func (*Scuttlebutt) LocalUpdate

func (sb *Scuttlebutt) LocalUpdate(any map[string]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

type Timestamp

type Timestamp int64

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

type Update

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

一次更新

func (*Update) MarshalJSON added in v1.1.0

func (u *Update) MarshalJSON() ([]byte, error)

todo.test

func (*Update) UnmarshalJSON added in v1.1.0

func (u *Update) UnmarshalJSON(data []byte) error

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