sbot

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 82 Imported by: 1

Documentation

Overview

Package sbot ties together network, repo and plugins like graph and blobs into a large server that offers data-access APIs and background replication. It's name dates back to a time where ssb-server was still called scuttlebot, in short: sbot.

Index

Constants

View Source
const FolderNameDelete = "drop-content-requests"

Variables

This section is empty.

Functions

func DropIndicies

func DropIndicies(r repo.Interface) error

Drop indicies deletes the following folders of the indexes. TODO: check that sbot isn't running?

func RebuildIndicies

func RebuildIndicies(path string) error

func ShutdownContext

func ShutdownContext(ctx context.Context) (context.Context, context.CancelFunc)

ShutdownContext returns a context that returns ssb.ErrShuttingDown when canceld. The server internals use this error to cleanly shut down index processing.

Types

type ErrConsistencyProblems

type ErrConsistencyProblems struct {
	Errors    []ssb.ErrWrongSequence
	Sequences *roaring.Bitmap
}

func (ErrConsistencyProblems) Error

func (e ErrConsistencyProblems) Error() string

type FSCKMode

type FSCKMode uint

FSCKMode is an enum for the sbot.FSCK function

const (

	// FSCKModeLength just checks the feed lengths
	FSCKModeLength FSCKMode

	// FSCKModeSequences makes sure the sequence field of each message on a feed are increasing correctly
	FSCKModeSequences
)

type FSCKOption

type FSCKOption func(*fsckOpt) error

func FSCKWithFeedIndex

func FSCKWithFeedIndex(idx multilog.MultiLog) FSCKOption

func FSCKWithMode

func FSCKWithMode(m FSCKMode) FSCKOption

func FSCKWithProgress

func FSCKWithProgress(fn FSCKUpdateFunc) FSCKOption

type FSCKUpdateFunc

type FSCKUpdateFunc func(percentage float64, timeLeft time.Duration)

FSCKUpdateFunc is called with the a percentage float between 0 and 100 and a durration who much time it should take, rounded to seconds.

type MetaFeeds added in v0.2.1

type MetaFeeds interface {
	// CreateSubFeed derives a new keypair, stores it in the keystore and publishes a `metafeed/add` message on the housing metafeed.
	// It takes purpose whic will be published and added to the keystore, too.
	// The subfeed will use the format
	CreateSubFeed(purpose string, format refs.RefAlgo) (refs.FeedRef, error)

	// TombstoneSubFeed removes the keypair from the store and publishes a `metafeed/tombstone` message to the feed.
	// Afterwards the referenced feed is unusable.
	TombstoneSubFeed(refs.FeedRef) error

	// ListSubFeeds returns a list of all _active_ subfeeds of the housing metafeed
	ListSubFeeds() ([]SubfeedListEntry, error)

	// Publish works like normal `Sbot.Publish()` but takes an additional feed reference,
	// which specifies the subfeed on which the content should be published.
	Publish(as refs.FeedRef, content interface{}) (refs.MessageRef, error)
}

MetaFeeds allows managing and publishing to subfeeds of a metafeed.

type MuxrpcEndpointWrapper

type MuxrpcEndpointWrapper func(muxrpc.Endpoint) muxrpc.Endpoint

MuxrpcEndpointWrapper can be used to wrap ever call a endpoint makes

type Option

type Option func(*Sbot) error

Option is a functional option type definition to change sbot behaviour

func DisableEBT

func DisableEBT(yes bool) Option

DisableEBT disables epidemic broadcast trees. It's a new implementation and might have some bugs.

func DisableLegacyLiveReplication

func DisableLegacyLiveReplication(yes bool) Option

DisableLegacyLiveReplication controls wether createHistoryStreams are created with live:true flag. This code is functional but might not scale to a lot of feeds. Therefore this flag can be used to force the old non-live polling mode.

func DisableLiveIndexMode

func DisableLiveIndexMode() Option

DisableLiveIndexMode makes the update processing halt once it reaches the end of the rootLog makes it easier to rebuild indicies.

func DisableNetworkNode

func DisableNetworkNode() Option

DisableNetworkNode disables all networking, in turn it only serves the database.

func EnableAdvertismentBroadcasts

func EnableAdvertismentBroadcasts(do bool) Option

EnableAdvertismentBroadcasts controls local peer discovery through sending UDP broadcasts

func EnableAdvertismentDialing

func EnableAdvertismentDialing(do bool) Option

EnableAdvertismentDialing controls local peer discovery through listening for and connecting to UDP broadcasts

func LateOption

func LateOption(o Option) Option

LateOption is a bit of a hack, it loads options after the _basic_ inititialisation is done (like repo location and keypair) this is mainly usefull for plugins that want to use a configured bot.

func MountMultiLog

func MountMultiLog(name string, fn repo.MakeMultiLog) Option

func MountPlugin

func MountPlugin(plug ssb.Plugin, mode plugins2.AuthMode) Option

func MountSimpleIndex

func MountSimpleIndex(name string, fn repo.MakeSimpleIndex) Option

func WithAppKey

func WithAppKey(k []byte) Option

WithAppKey changes the appkey (aka secret-handshake network cap). See https://ssbc.github.io/scuttlebutt-protocol-guide/#handshake for more.

func WithBlobStore

func WithBlobStore(bs ssb.BlobStore) Option

WithBlobStore can be used to use a different storage backend for blobs.

func WithContext

func WithContext(ctx context.Context) Option

WithContext changes the context that is context.Background() by default. Handy to setup cancelation against a interup signal like ctrl+c. Canceling the context also shuts down indexing. If no context is passed sbot.Shutdown() can be used.

func WithDialer

func WithDialer(dial netwrap.Dialer) Option

WithDialer changes the function that is used to dial remote peers. This could be a sock5 connection builder to support tor proxying to hidden services.

func WithEndpointWrapper

func WithEndpointWrapper(mw MuxrpcEndpointWrapper) Option

WithEndpointWrapper sets a MuxrpcEndpointWrapper for new connections.

func WithEventMetrics

func WithEventMetrics(ctr metrics.Counter, lvls metrics.Gauge, lat metrics.Histogram) Option

WithEventMetrics sets up latency and counter metrics

func WithHMACSigning

func WithHMACSigning(key []byte) Option

WithHMACSigning sets an HMAC signing key for messages. Useful for testing, see https://github.com/ssb-js/ssb-validate#state--validateappendstate-hmac_key-msg for more.

func WithHops

func WithHops(h uint) Option

WithHops sets the number of friends (or bi-directionla follows) to walk between two peers controls fetch depth (whos feeds to fetch. 0: only my own follows 1: my friends follows 2: also their friends follows and how many hops a peer can be from self to for a connection to be accepted

func WithInfo

func WithInfo(log kitlog.Logger) Option

WithInfo changes the info/warn/debug loging output.

func WithJSONKeyPair

func WithJSONKeyPair(blob string) Option

WithJSONKeyPair expectes a JSON-string as blob and calls ssb.ParseKeyPair on it. This is useful if you dont't want to place the keypair on the filesystem.

func WithKeyPair

func WithKeyPair(kp ssb.KeyPair) Option

WithKeyPair exepect a initialized ssb.KeyPair. Useful for testing.

func WithListenAddr

func WithListenAddr(addr string) Option

WithListenAddr changes the muxrpc listener address. By default it listens to ':8008'.

func WithMetaFeedMode added in v0.2.1

func WithMetaFeedMode(enable bool) Option

WithMetaFeedMode enables metafeed support. It switches the default keypair to bendybutt and initializes the MetaFeed API of the Sbot.

func WithNamedKeyPair

func WithNamedKeyPair(name string) Option

WithNamedKeyPair changes from the default `secret` file, useful for testing.

func WithNetworkConnTracker

func WithNetworkConnTracker(ct ssb.ConnTracker) Option

WithNetworkConnTracker changes the connection tracker. See network.NewLastWinsTracker and network.NewAcceptAllTracker.

func WithPostSecureConnWrapper

func WithPostSecureConnWrapper(cw netwrap.ConnWrapper) Option

WithPostSecureConnWrapper wrapps the connection before it is encrypted. Usefull to insepct the muxrpc frames before they go into boxstream.

func WithPreSecureConnWrapper

func WithPreSecureConnWrapper(cw netwrap.ConnWrapper) Option

WithPreSecureConnWrapper wrapps the connection after it is encrypted. Usefull for debugging and measuring traffic.

func WithPromisc

func WithPromisc(yes bool) Option

WithPromisc when enabled bypasses graph-distance lookups on connections and makes the gossip handler fetch the remotes feed

func WithPublicAuthorizer

func WithPublicAuthorizer(auth ssb.Authorizer) Option

WithPublicAuthorizer configures who is considered "public" when accepting connections. By default, this is covered by the list of followed and blocked peers using the graph implementation.

func WithReplicator

func WithReplicator(r ssb.Replicator) Option

WithReplicator overwrites the default graph based decision maker, of which feeds to copy or block

func WithRepoPath

func WithRepoPath(path string) Option

WithRepoPath changes where the replication database and blobs are stored.

func WithUNIXSocket

func WithUNIXSocket() Option

WithUNIXSocket enables listening for muxrpc connections on a unix socket files ($repo/socket). This socket is not encrypted or authenticated since access to it is mediated by filesystem ownership.

func WithWebsocketAddress

func WithWebsocketAddress(addr string) Option

WithWebsocketAddress changes the HTTP listener address, by default it's :8989.

type Sbot

type Sbot struct {

	// Shutdown needs to be called to shutdown indexing
	Shutdown context.CancelFunc

	Network *network.Node

	KeyPair ssb.KeyPair

	Groups *private.Manager

	ReceiveLog multimsg.AlterableLog // the stream of messages as they arrived

	SeqResolver *repo.SequenceResolver

	PublishLog ssb.Publisher

	// hardcoded default indexes
	Users   *roaring.MultiLog // one sublog per feed
	Private *roaring.MultiLog // one sublog per keypair
	ByType  *roaring.MultiLog // one sublog per type: ... (special cases for private messages by suffix)
	Tangles *roaring.MultiLog // one sublog per root:%ref (actual root is in the get index)

	GraphBuilder graph.Builder

	BlobStore   ssb.BlobStore
	WantManager ssb.WantManager

	MetaFeeds MetaFeeds

	ssb.Replicator
	// contains filtered or unexported fields
}

Sbot is the database and replication server

func New

func New(fopts ...Option) (*Sbot, error)

New creates an sbot instance using the passed options to configure it.

func (*Sbot) Close

func (s *Sbot) Close() error

Close closes the bot by stopping network connections and closing the internal databases

func (*Sbot) CurrentSequence

func (s *Sbot) CurrentSequence(feed refs.FeedRef) (ssb.Note, error)

func (*Sbot) DontReplicate

func (sbot *Sbot) DontReplicate(r refs.FeedRef)

func (*Sbot) FSCK

func (s *Sbot) FSCK(opts ...FSCKOption) error

FSCK checks the consistency of the received messages and the indexes. progressFn offers a way to track the progress. It's okay to pass nil, the set sbot.info logger is used in that case.

func (Sbot) Get

func (s Sbot) Get(ref refs.MessageRef) (refs.Message, error)

func (*Sbot) GetIndexNamesMultiLog

func (s *Sbot) GetIndexNamesMultiLog() []string

func (*Sbot) GetIndexNamesSimple

func (s *Sbot) GetIndexNamesSimple() []string

func (*Sbot) GetMultiLog

func (s *Sbot) GetMultiLog(name string) (multilog.MultiLog, bool)

func (*Sbot) GetSimpleIndex

func (s *Sbot) GetSimpleIndex(name string) (librarian.Index, bool)

func (*Sbot) HealRepo

func (s *Sbot) HealRepo(report ErrConsistencyProblems) error

HealRepo just nulls the messages and is a very naive repair but the only one that is feasably implemented right now

func (*Sbot) NullContent

func (s *Sbot) NullContent(fr refs.FeedRef, seq uint) error

NullContent drops the content portion of a gabbygrove transfer. seq is in the same base ase the feed (starting with 1).

func (*Sbot) NullFeed

func (s *Sbot) NullFeed(ref refs.FeedRef) error

NullFeed overwrites all the entries from ref in repo with zeros

func (*Sbot) PublishAs

func (sbot *Sbot) PublishAs(nick string, val interface{}) (refs.MessageRef, error)

func (*Sbot) Replicate

func (sbot *Sbot) Replicate(r refs.FeedRef)

func (*Sbot) Status

func (sbot *Sbot) Status() (ssb.Status, error)

func (*Sbot) WaitUntilIndexesAreSynced

func (s *Sbot) WaitUntilIndexesAreSynced()

WaitUntilIndexesAreSynced blocks until all the index processing is in sync with the rootlog

type SubfeedListEntry added in v0.2.1

type SubfeedListEntry struct {
	Feed    refs.FeedRef
	Purpose string
}

Jump to

Keyboard shortcuts

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