ssb

package module
v0.0.0-...-eeb6358 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2018 License: GPL-3.0 Imports: 20 Imported by: 0

README

Go-ssb

Go-ssb is an implementation of secure-scuttlebutt in Golang.

Getting Started
# Clone the repo and dependencies into your gopath
go get github.com/andyleap/go-ssb/...

# Build the sbot executable
cd go/src/github.com/andyleap/go-ssb/cmd/sbot
go build

# Run the executable
./sbot

# Point a web browser at localhost:9823 to use the client
# Go to localhost:9823/admin to add a pub invite and connect to the network

Join us in #scuttlebutt-go on freenode.

Documentation

Overview

go-ssb document

go-ssb project go-ssb.go

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRefType = errors.New("Invalid Ref Type")
	ErrInvalidRefAlgo = errors.New("Invalid Ref Algo")
	ErrInvalidSig     = errors.New("Invalid Signature")
	ErrInvalidHash    = errors.New("Invalid Hash")
)
View Source
var AddMessageHooks = map[string]func(m *SignedMessage, tx *bolt.Tx) error{}
View Source
var Compression1 = []byte(`{
  "previous": ",
  "author": ",
  "sequence": ,
  "timestamp": ,
  "hash": "sha256",
  "content": {
    "type": "about"contact"post"vote",
    "text": ",
    "channel": ",
    "root": ",
    "branch": ",
    "recps": ",
    "mentions": [],
    "about": ",
    "name": ",
    "image": ",
    "contact": ",
    "following": true,
	"blocking": false,
	"vote": {
      "link": ",
      "value": 1,
      "reason": "Dug"
    }
    "repo": ",
  }
  "signature: ",
}`)
View Source
var Compression2 = []byte(`{
  "previous": ",
  "author": ",
  "sequence": ,
  "timestamp": ,
  "hash": "sha256",
  "content": {
    "type": "about"contact"post"vote",
    "text": ",
    "channel": ",
    "root": ",
    "branch": ",
    "recps": ",
    "mentions": [],
    "about": ",
    "name": ",
    "image": ",
    "contact": ",
    "following": true,
	"blocking": false,
	"vote": {
      "link": ",
      "value": 1,
      "reason": "Dug"
    }
    "repo": "
  }
  "signature: "
}`)
View Source
var ErrLogClosed = errors.New("LogClosed")
View Source
var MessageTypes = map[string]func(mb MessageBody) interface{}{}
View Source
var RebuildClearHooks = map[string]func(tx *bolt.Tx) error{}

Functions

func Encode

func Encode(i interface{}) ([]byte, error)

func RegisterInit

func RegisterInit(f func(ds *DataStore))

func RemoveUnsupported

func RemoveUnsupported(e *encoding.Encoder) *encoding.Encoder

func ToJSBinary

func ToJSBinary(src []byte) []byte

Types

type DataStore

type DataStore struct {
	Topic *MessageTopic

	PrimaryKey *secrethandshake.EdKeyPair
	PrimaryRef Ref

	Keys map[Ref]Signer
	// contains filtered or unexported fields
}

func OpenDataStore

func OpenDataStore(path string, primaryKey *secrethandshake.EdKeyPair) (*DataStore, error)

func (*DataStore) Close

func (ds *DataStore) Close()

func (*DataStore) DB

func (ds *DataStore) DB() *bolt.DB

func (*DataStore) ExtraData

func (ds *DataStore) ExtraData(name string) interface{}

func (*DataStore) Get

func (ds *DataStore) Get(tx *bolt.Tx, post Ref) (m *SignedMessage)

func (*DataStore) GetFeed

func (ds *DataStore) GetFeed(feedID Ref) *Feed

func (*DataStore) LatestCountFiltered

func (ds *DataStore) LatestCountFiltered(num int, start int, filter map[Ref]int) (msgs []*SignedMessage)

func (*DataStore) Rebuild

func (ds *DataStore) Rebuild(module string)

func (*DataStore) RebuildAll

func (ds *DataStore) RebuildAll()

func (*DataStore) RegisterMethod

func (ds *DataStore) RegisterMethod(name string, method interface{})

func (*DataStore) SetExtraData

func (ds *DataStore) SetExtraData(name string, data interface{})

type Feed

type Feed struct {
	ID Ref

	Topic     *MessageTopic
	LatestSeq int
	SeqLock   sync.Mutex
	// contains filtered or unexported fields
}

func (*Feed) AddMessage

func (f *Feed) AddMessage(m *SignedMessage) error

func (*Feed) Follow

func (f *Feed) Follow(seq int, live bool, handler func(m *SignedMessage) error, done chan struct{}) error

func (*Feed) GetSeq

func (f *Feed) GetSeq(tx *bolt.Tx, seq int) (m *SignedMessage)

func (*Feed) Latest

func (f *Feed) Latest() (m *SignedMessage)

func (*Feed) LatestCount

func (f *Feed) LatestCount(num int, start int) (msgs []*SignedMessage)

func (*Feed) Log

func (f *Feed) Log(seq int, live bool) chan *SignedMessage

func (*Feed) PublishMessage

func (f *Feed) PublishMessage(body interface{}) error

type Message

type Message struct {
	Previous  *Ref            `json:"previous"`
	Author    Ref             `json:"author"`
	Sequence  int             `json:"sequence"`
	Timestamp float64         `json:"timestamp"`
	Hash      string          `json:"hash"`
	Content   json.RawMessage `json:"content"`
}

func (*Message) DecodeMessage

func (m *Message) DecodeMessage() (t string, mb interface{})

func (*Message) Sign

func (m *Message) Sign(s Signer) *SignedMessage

func (*Message) Type

func (m *Message) Type() string

type MessageBody

type MessageBody struct {
	Type    string   `json:"type"`
	Message *Message `json:"-"`
}

type MessageTopic

type MessageTopic struct {
	Send chan *SignedMessage
	// contains filtered or unexported fields
}

func NewMessageTopic

func NewMessageTopic() *MessageTopic

func (*MessageTopic) Close

func (mt *MessageTopic) Close()

func (*MessageTopic) Register

func (mt *MessageTopic) Register(recp chan *SignedMessage, strict bool) chan *SignedMessage

func (*MessageTopic) Unregister

func (mt *MessageTopic) Unregister(recp chan *SignedMessage)

type Pointer

type Pointer struct {
	Sequence int
	LogKey   int
	Author   []byte
}

func (Pointer) Marshal

func (p Pointer) Marshal() []byte

func (*Pointer) Unmarshal

func (p *Pointer) Unmarshal(buf []byte)

type Ref

type Ref struct {
	Type RefType
	Data string
	Algo RefAlgo
}

func DBRef

func DBRef(ref []byte) Ref

func NewRef

func NewRef(typ RefType, raw []byte, algo RefAlgo) (Ref, error)

func ParseRef

func ParseRef(ref string) Ref

func (Ref) CheckHash

func (r Ref) CheckHash(content []byte) error

func (Ref) DBKey

func (r Ref) DBKey() []byte

func (Ref) IsMessage

func (r Ref) IsMessage() bool

func (Ref) MarshalText

func (r Ref) MarshalText() (text []byte, err error)

func (Ref) Raw

func (r Ref) Raw() []byte

func (Ref) String

func (r Ref) String() string

func (*Ref) UnmarshalText

func (r *Ref) UnmarshalText(text []byte) error

type RefAlgo

type RefAlgo int
const (
	RefAlgoInvalid RefAlgo = iota
	RefAlgoSha256
	RefAlgoEd25519
)

func (RefAlgo) String

func (ra RefAlgo) String() string

type RefType

type RefType int
const (
	RefInvalid RefType = iota
	RefFeed
	RefMessage
	RefBlob
)

func (RefType) String

func (rt RefType) String() string

type SigAlgo

type SigAlgo int
const (
	SigAlgoInvalid SigAlgo = iota
	SigAlgoEd25519
)

type Signature

type Signature string

func (Signature) Algo

func (s Signature) Algo() SigAlgo

func (Signature) Raw

func (s Signature) Raw() []byte

func (Signature) Verify

func (s Signature) Verify(content []byte, r Ref) error

type SignedMessage

type SignedMessage struct {
	Message
	Signature Signature `json:"signature"`
}

func DecompressMessage

func DecompressMessage(cbuf []byte) *SignedMessage

func GetMsg

func GetMsg(tx *bolt.Tx, post Ref) (m *SignedMessage)

func (*SignedMessage) Compress

func (m *SignedMessage) Compress() []byte

func (*SignedMessage) Encode

func (m *SignedMessage) Encode() []byte

func (*SignedMessage) Key

func (m *SignedMessage) Key() Ref

func (*SignedMessage) Verify

func (m *SignedMessage) Verify(tx *bolt.Tx, f *Feed) error

type Signer

type Signer interface {
	Sign([]byte) Signature
}

type SignerEd25519

type SignerEd25519 struct {
	Private ed25519.PrivateKey
}

func (SignerEd25519) Sign

func (k SignerEd25519) Sign(content []byte) Signature

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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