ssb: Index | Files | Directories

package ssb

import ""


Package Files

auth.go blobstore.go errors.go keys.go messages.go network.go plugin.go refs.go refs_binary.go sbot.go


const (
    RefAlgoFeedSSB1    = "ed25519" // ssb v1 (legacy, crappy encoding)
    RefAlgoMessageSSB1 = "sha256"  // scuttlebutt happend anyway
    RefAlgoBlobSSB1    = RefAlgoMessageSSB1

    RefAlgoFeedGabby    = "ggfeed-v1" // cbor based chain
    RefAlgoMessageGabby = "ggmsg-v1"

    RefAlgoContentGabby = "gabby-v1-content"

Some constant identifiers

const DropContentRequestType = "drop-content-request"
const SecretPerms os.FileMode = 0600

SecretPerms are the file permissions for holding SSB secrets.


var (
    ErrInvalidRef     = stderr.New("ssb: Invalid Ref")
    ErrInvalidRefType = stderr.New("ssb: Invalid Ref Type")
    ErrInvalidRefAlgo = stderr.New("ssb: Invalid Ref Algo")
    ErrInvalidSig     = stderr.New("ssb: Invalid Signature")
    ErrInvalidHash    = stderr.New("ssb: Invalid Hash")

Common errors for invalid references

var ErrShuttingDown = errors.Errorf("ssb: shutting down now") // this is fine
var ErrUnuspportedFormat = errors.Errorf("ssb: unsupported format")

func EncodeKeyPairAsJSON Uses

func EncodeKeyPairAsJSON(kp *KeyPair, w io.Writer) error

func FeedsWithSequnce Uses

func FeedsWithSequnce(feedIndex multilog.MultiLog) (luigi.Source, error)

FeedsWithSequnce returns a source that emits one ReplicateUpToResponse per stored feed in feedIndex TODO: make cancelable and with no RAM overhead when only partially used (iterate on demand)

func IsMessageUnusable Uses

func IsMessageUnusable(err error) bool

func IsValidFeedFormat Uses

func IsValidFeedFormat(r *FeedRef) error

func NewFeedRefLenError Uses

func NewFeedRefLenError(n int) error

func NewHashLenError Uses

func NewHashLenError(n int) error

func SaveKeyPair Uses

func SaveKeyPair(kp *KeyPair, path string) error

type About Uses

type About struct {
    Type        string   `json:"type"`
    About       *FeedRef `json:"about"`
    Name        string   `json:"name,omitempty"`
    Description string   `json:"description,omitempty"`
    Image       *BlobRef `json:"image,omitempty"`

func NewAboutImage Uses

func NewAboutImage(who *FeedRef, img *BlobRef) *About

func NewAboutName Uses

func NewAboutName(who *FeedRef, name string) *About

func (*About) UnmarshalJSON Uses

func (a *About) UnmarshalJSON(b []byte) error

type AnyRef Uses

type AnyRef struct {
    // contains filtered or unexported fields

func (AnyRef) IsBlob Uses

func (ar AnyRef) IsBlob() (*BlobRef, bool)

func (*AnyRef) MarshalJSON Uses

func (ar *AnyRef) MarshalJSON() ([]byte, error)

func (AnyRef) Ref Uses

func (ar AnyRef) Ref() string

func (AnyRef) ShortRef Uses

func (ar AnyRef) ShortRef() string

func (*AnyRef) UnmarshalJSON Uses

func (ar *AnyRef) UnmarshalJSON(b []byte) error

type Authorizer Uses

type Authorizer interface {
    Authorize(remote *FeedRef) error

type BlobRef Uses

type BlobRef struct {
    Hash []byte
    Algo string

BlobRef defines a static binary attachment reference, identified it's hash.

func ParseBlobRef Uses

func ParseBlobRef(s string) (*BlobRef, error)

ParseBlobRef uses ParseRef and checks that it returns a *BlobRef

func (BlobRef) Equal Uses

func (ref BlobRef) Equal(b *BlobRef) bool

func (BlobRef) IsValid Uses

func (br BlobRef) IsValid() error

func (BlobRef) MarshalText Uses

func (br BlobRef) MarshalText() ([]byte, error)

MarshalText encodes the BlobRef using Ref()

func (BlobRef) Ref Uses

func (ref BlobRef) Ref() string

Ref returns the BlobRef with the sigil &, it's base64 encoded hash and the used algo (currently only sha256)

func (BlobRef) ShortRef Uses

func (ref BlobRef) ShortRef() string

func (*BlobRef) UnmarshalText Uses

func (br *BlobRef) UnmarshalText(text []byte) error

UnmarshalText uses ParseBlobRef

type BlobStore Uses

type BlobStore interface {
    // Get returns a reader of the blob with given ref.
    Get(ref *BlobRef) (io.Reader, error)

    // Put stores the data in the reader in the blob store and returns the address.
    Put(blob io.Reader) (*BlobRef, error)

    // Delete deletes a blob from the blob store.
    Delete(ref *BlobRef) error

    // List returns a source of the refs of all stored blobs.
    List() luigi.Source

    // Size returns the size of the blob with given ref.
    Size(ref *BlobRef) (int64, error)

    // Changes returns a broadcast that emits put and remove notifications.
    Changes() luigi.Broadcast

BlobStore is the interface of our blob store go:generate go run -o mock/blobstore.go . BlobStore

type BlobStoreNotification Uses

type BlobStoreNotification struct {
    Op  BlobStoreOp
    Ref *BlobRef

BlobStoreNotification contains info on a single change of the blob store. Op is either "rm" or "put".

func (BlobStoreNotification) String Uses

func (bn BlobStoreNotification) String() string

type BlobStoreOp Uses

type BlobStoreOp string

BlobStoreOp specifies the operation in a blob store notification.

const (
    // BlobStoreOpPut is used in put notifications
    BlobStoreOpPut BlobStoreOp = "put"

    // BlobStoreOpRm is used in remove notifications
    BlobStoreOpRm BlobStoreOp = "rm"

func (BlobStoreOp) String Uses

func (op BlobStoreOp) String() string

String returns the string representation of the operation.

type BlobWant Uses

type BlobWant struct {
    Ref *BlobRef

    // if Dist is negative, it is the hop count to the original wanter.
    // if it is positive, it is the size of the blob.
    Dist int64

func (BlobWant) String Uses

func (w BlobWant) String() string

type ConnTracker Uses

type ConnTracker interface {
    // Active returns true and since when a peer connection is active
    Active(net.Addr) (bool, time.Duration)

    // OnAccept receives a new connection as an argument.
    // If it decides to accept it, it returns true and a context that will be canceled once it should shut down
    // If it decides to deny it, it returns false (and a nil context)
    OnAccept(context.Context, net.Conn) (bool, context.Context)

    // OnClose notifies the tracker that a connection was closed
    OnClose(conn net.Conn) time.Duration

    // Count returns the number of open connections
    Count() uint

    // CloseAll closes all tracked connections

ConnTracker decides if connections should be established and keeps track of them

type Contact Uses

type Contact struct {
    Type      string   `json:"type"`
    Contact   *FeedRef `json:"contact"`
    Following bool     `json:"following"`
    Blocking  bool     `json:"blocking"`

func NewContactBlock Uses

func NewContactBlock(who *FeedRef) *Contact

func NewContactFollow Uses

func NewContactFollow(who *FeedRef) *Contact

func (*Contact) UnmarshalJSON Uses

func (c *Contact) UnmarshalJSON(b []byte) error

type ContentNuller Uses

type ContentNuller interface {
    NullContent(feed *FeedRef, seq uint) error

type ContentRef Uses

type ContentRef struct {
    Hash []byte
    Algo string

ContentRef defines the hashed content of a message

func (ContentRef) MarshalBinary Uses

func (ref ContentRef) MarshalBinary() ([]byte, error)

func (ContentRef) Ref Uses

func (ref ContentRef) Ref() string

func (ContentRef) ShortRef Uses

func (ref ContentRef) ShortRef() string

func (*ContentRef) UnmarshalBinary Uses

func (ref *ContentRef) UnmarshalBinary(data []byte) error

type DropContentRequest Uses

type DropContentRequest struct {
    Type     string     `json:"type"`
    Sequence uint       `json:"sequence"`
    Hash     MessageRef `json:"hash"`

DropContentRequest has special meaning on a gabby-grove feed. It's signature verification allows ommiting the content. A feed author can ask other peers to drop a previous message of theirs with this. Sequence must be smaller then current, also the targeted message can't be a drop-content-request

func NewDropContentRequest Uses

func NewDropContentRequest(seq uint, h MessageRef) *DropContentRequest

func (DropContentRequest) Valid Uses

func (dcr DropContentRequest) Valid(log margaret.Log) bool

type EndpointStat Uses

type EndpointStat struct {
    ID       *FeedRef
    Addr     net.Addr
    Since    time.Duration
    Endpoint muxrpc.Endpoint

EndpointStat gives some information about a connected peer

type ErrMalfromedMsg Uses

type ErrMalfromedMsg struct {
    // contains filtered or unexported fields

func (ErrMalfromedMsg) Error Uses

func (emm ErrMalfromedMsg) Error() string

type ErrOutOfReach Uses

type ErrOutOfReach struct {
    Dist int
    Max  int

func (ErrOutOfReach) Error Uses

func (e ErrOutOfReach) Error() string

type ErrRefLen Uses

type ErrRefLen struct {
    // contains filtered or unexported fields

func (ErrRefLen) Error Uses

func (e ErrRefLen) Error() string

type ErrWrongSequence Uses

type ErrWrongSequence struct {
    Ref             *FeedRef
    Logical, Stored margaret.Seq

ErrWrongSequence is returned if there is a glitch on the current sequence number on the feed between in the offsetlog and the logical entry on the feed

func (ErrWrongSequence) Error Uses

func (e ErrWrongSequence) Error() string

type ErrWrongType Uses

type ErrWrongType struct {
    // contains filtered or unexported fields

func (ErrWrongType) Error Uses

func (ewt ErrWrongType) Error() string

type FeedRef Uses

type FeedRef struct {
    ID   []byte
    Algo string

FeedRef defines a publickey as ID with a specific algorithm (currently only ed25519)

func GetFeedRefFromAddr Uses

func GetFeedRefFromAddr(addr net.Addr) (*FeedRef, error)

GetFeedRefFromAddr uses netwrap to get the secretstream address and then uses ParseFeedRef

func ParseFeedRef Uses

func ParseFeedRef(s string) (*FeedRef, error)

ParseFeedRef uses ParseRef and checks that it returns a *FeedRef

func (FeedRef) Equal Uses

func (ref FeedRef) Equal(b *FeedRef) bool

func (FeedRef) MarshalText Uses

func (fr FeedRef) MarshalText() ([]byte, error)

func (FeedRef) PubKey Uses

func (ref FeedRef) PubKey() ed25519.PublicKey

func (FeedRef) Ref Uses

func (ref FeedRef) Ref() string

func (*FeedRef) Scan Uses

func (r *FeedRef) Scan(raw interface{}) error

func (FeedRef) ShortRef Uses

func (ref FeedRef) ShortRef() string

func (FeedRef) StoredAddr Uses

func (ref FeedRef) StoredAddr() librarian.Addr

StoredAddr returns the key under which this ref is stored in the multilog system

func (*FeedRef) UnmarshalText Uses

func (fr *FeedRef) UnmarshalText(text []byte) error

type Getter Uses

type Getter interface {
    Get(MessageRef) (Message, error)

type Indexer Uses

type Indexer interface {
    GetIndexNamesSimple() []string
    GetIndexNamesMultiLog() []string

type KeyPair Uses

type KeyPair struct {
    Id   *FeedRef
    Pair secrethandshake.EdKeyPair

func LoadKeyPair Uses

func LoadKeyPair(fname string) (*KeyPair, error)

LoadKeyPair opens fname, ignores any line starting with # and passes it ParseKeyPair

func NewKeyPair Uses

func NewKeyPair(r io.Reader) (*KeyPair, error)

func ParseKeyPair Uses

func ParseKeyPair(r io.Reader) (*KeyPair, error)

ParseKeyPair json decodes an object from the reader. It expects std base64 encoded data under the `private` and `public` fields.

type KeyValueAsMap Uses

type KeyValueAsMap struct {
    Key       *MessageRef           `json:"key"`
    Value     Value                 `json:"value"`
    Timestamp encodedTime.Millisecs `json:"timestamp"`

type KeyValueRaw Uses

type KeyValueRaw struct {
    Key_      *MessageRef           `json:"key"`
    Value     Value                 `json:"value"`
    Timestamp encodedTime.Millisecs `json:"timestamp"`

func (KeyValueRaw) Author Uses

func (kvr KeyValueRaw) Author() *FeedRef

func (KeyValueRaw) Claimed Uses

func (kvr KeyValueRaw) Claimed() time.Time

func (KeyValueRaw) ContentBytes Uses

func (kvr KeyValueRaw) ContentBytes() []byte

func (KeyValueRaw) Key Uses

func (kvr KeyValueRaw) Key() *MessageRef

func (KeyValueRaw) Previous Uses

func (kvr KeyValueRaw) Previous() *MessageRef

func (KeyValueRaw) Received Uses

func (kvr KeyValueRaw) Received() time.Time

func (KeyValueRaw) Seq Uses

func (kvr KeyValueRaw) Seq() int64

func (KeyValueRaw) ValueContent Uses

func (kvr KeyValueRaw) ValueContent() *Value

func (KeyValueRaw) ValueContentJSON Uses

func (kvr KeyValueRaw) ValueContentJSON() json.RawMessage

type Mention Uses

type Mention struct {
    Link AnyRef `json:"link,omitempty"`
    Name string `json:"name,omitempty"`

func NewMention Uses

func NewMention(r Ref, name string) Mention

type Message Uses

type Message interface {
    Key() *MessageRef
    Previous() *MessageRef


    Claimed() time.Time
    Received() time.Time

    Author() *FeedRef
    ContentBytes() []byte

    ValueContent() *Value
    ValueContentJSON() json.RawMessage

Message allows accessing message aspects without known the feed type

type MessageRef Uses

type MessageRef struct {
    Hash []byte
    Algo string

MessageRef defines the content addressed version of a ssb message, identified it's hash.

func ParseMessageRef Uses

func ParseMessageRef(s string) (*MessageRef, error)

func (MessageRef) Equal Uses

func (ref MessageRef) Equal(other MessageRef) bool

func (MessageRef) MarshalText Uses

func (mr MessageRef) MarshalText() ([]byte, error)

func (MessageRef) Ref Uses

func (ref MessageRef) Ref() string

Ref prints the full identifieir

func (*MessageRef) Scan Uses

func (r *MessageRef) Scan(raw interface{}) error

func (MessageRef) ShortRef Uses

func (ref MessageRef) ShortRef() string

ShortRef prints a shortend version

func (*MessageRef) UnmarshalText Uses

func (mr *MessageRef) UnmarshalText(text []byte) error

type MessageRefs Uses

type MessageRefs []*MessageRef

func (*MessageRefs) String Uses

func (mr *MessageRefs) String() string

func (*MessageRefs) UnmarshalJSON Uses

func (mr *MessageRefs) UnmarshalJSON(text []byte) error

type MultiLogGetter Uses

type MultiLogGetter interface {
    GetMultiLog(name string) (multilog.MultiLog, bool)

type Network Uses

type Network interface {
    Connect(ctx context.Context, addr net.Addr) error
    Serve(context.Context, ...muxrpc.HandlerWrapper) error
    GetListenAddr() net.Addr

    GetAllEndpoints() []EndpointStat
    GetEndpointFor(*FeedRef) (muxrpc.Endpoint, bool)

    GetConnTracker() ConnTracker


type OldAddress Uses

type OldAddress struct {
    Host string  `json:"host"`
    Port int     `json:"port"`
    Key  FeedRef `json:"key"`

OldAddress uses an ssb.FeedRef as a key this is not strictly necessary since secret-handshake only cares about the 32bytes of public key (and not the feed type) newer type:address uses multiserver and not this nested object

type OldPubMessage Uses

type OldPubMessage struct {
    Type    string     `json:"type"`
    Address OldAddress `json:"address"`

OldPubMessage is posted after a legacy invite is used to advertise a pub to your followers

type PeerStatus Uses

type PeerStatus struct {
    Addr  string
    Since string

type Plugin Uses

type Plugin interface {
    // Name returns the name and version of the plugin.
    // format: name-1.0.2
    Name() string

    // Method returns the preferred method of the call
    Method() muxrpc.Method

    // Handler returns the muxrpc handler for the plugin
    Handler() muxrpc.Handler

type PluginManager Uses

type PluginManager interface {
    MakeHandler(conn net.Conn) (muxrpc.Handler, error)

func NewPluginManager Uses

func NewPluginManager() PluginManager

type Post Uses

type Post struct {
    Type     string      `json:"type"`
    Text     string      `json:"text"`
    Root     *MessageRef `json:"root,omitempty"`
    Branch   MessageRefs `json:"branch,omitempty"`
    Mentions []Mention   `json:"mentions,omitempty"`

type Publisher Uses

type Publisher interface {

    // Publish is a utility wrapper around append which returns the new message reference key
    Publish(content interface{}) (*MessageRef, error)

type Ref Uses

type Ref interface {
    Ref() string
    ShortRef() string

func ParseRef Uses

func ParseRef(str string) (Ref, error)

type ReplicateUpToResponse Uses

type ReplicateUpToResponse struct {
    ID       FeedRef `json:"id"`
    Sequence int64   `json:"sequence"`

this is one message of replicate.upto also handy to talk about the (latest) state of a single feed

func (ReplicateUpToResponse) Seq Uses

func (upto ReplicateUpToResponse) Seq() int64

type SimpleIndexGetter Uses

type SimpleIndexGetter interface {
    GetSimpleIndex(name string) (librarian.Index, bool)

type Status Uses

type Status struct {
    PID   int // process id of the bot
    Peers []PeerStatus
    Blobs []BlobWant
    Root  margaret.BaseSeq

type Statuser Uses

type Statuser interface {
    Status() (Status, error)

type StorageRef Uses

type StorageRef struct {
    // contains filtered or unexported fields

StorageRef is used as an compact internal storage representation

func NewStorageRef Uses

func NewStorageRef(r Ref) (*StorageRef, error)

func NewStorageRefFromString Uses

func NewStorageRefFromString(s string) (*StorageRef, error)

func (StorageRef) FeedRef Uses

func (ref StorageRef) FeedRef() (*FeedRef, error)

func (StorageRef) GetRef Uses

func (ref StorageRef) GetRef(t StorageRefType) (Ref, error)

func (StorageRef) Marshal Uses

func (ref StorageRef) Marshal() ([]byte, error)

func (StorageRef) MarshalJSON Uses

func (ref StorageRef) MarshalJSON() ([]byte, error)

func (*StorageRef) MarshalTo Uses

func (ref *StorageRef) MarshalTo(data []byte) (n int, err error)

func (StorageRef) Ref Uses

func (ref StorageRef) Ref() string

func (StorageRef) ShortRef Uses

func (ref StorageRef) ShortRef() string

func (StorageRef) StoredAddr Uses

func (ref StorageRef) StoredAddr() librarian.Addr

func (StorageRef) String Uses

func (ref StorageRef) String() string

func (*StorageRef) Unmarshal Uses

func (ref *StorageRef) Unmarshal(data []byte) error

func (*StorageRef) UnmarshalJSON Uses

func (ref *StorageRef) UnmarshalJSON(data []byte) error

type StorageRefType Uses

type StorageRefType byte
const (
    StorageRefUndefined StorageRefType = iota

enum of StorageRefTypes

type Typed Uses

type Typed struct {
    Content struct {
        Type string `json:"type"`
    }   `json:"content"`

type Value Uses

type Value struct {
    Previous  *MessageRef           `json:"previous"`
    Author    FeedRef               `json:"author"`
    Sequence  margaret.BaseSeq      `json:"sequence"`
    Timestamp encodedTime.Millisecs `json:"timestamp"`
    Hash      string                `json:"hash"`
    Content   json.RawMessage       `json:"content"`
    Signature string                `json:"signature"`

type ValuePost Uses

type ValuePost struct {
    Content Post `json:"content"`

type ValueVote Uses

type ValueVote struct {
    Content Vote `json:"content"`

type Vote Uses

type Vote struct {
    Type string `json:"type"`
    Vote struct {
        Expression string      `json:"expression"`
        Link       *MessageRef `json:"link"`
        Value      int         `json:"value"`
    }   `json:"vote"`

type WantManager Uses

type WantManager interface {
    Want(ref *BlobRef) error
    Wants(ref *BlobRef) bool
    WantWithDist(ref *BlobRef, dist int64) error
    //Unwant(ref *BlobRef) error
    CreateWants(context.Context, luigi.Sink, muxrpc.Endpoint) luigi.Sink

    AllWants() []BlobWant

go:generate go run -o mock/wantmanager.go . WantManager


cmd/sbotclisbotcli implements a simple tool to query commands on another sbot
cmd/ssb-drop-feedssb-drop-feed nulls entries of one particular feed from repo there is no warning or undo
internal/extra25519blatent grep of until we have a better solution
internal/leakcheckPackage leakcheck contains functions to check leaked goroutines.
internal/toolsmainly used to install
mockCode generated by counterfeiter.

Package ssb imports 26 packages (graph) and is imported by 81 packages. Updated 2020-05-18. Refresh now. Tools for package owners.