repo

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2018 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const MAGIC string = "000000000000000000000000"

Variables

View Source
var ErrRepoExists = errors.New("repo not empty, reinitializing would overwrite your keys")

Functions

func CreatePointerKey

func CreatePointerKey(mh multihash.Multihash, prefixLen int) multihash.Multihash

func DoInit

func DoInit(repoRoot string, version string, mnemonic *string, initDB func(string) error, initConfig func(time.Time) error) (string, error)

func FindPointers

func FindPointers(dht *routing.IpfsDHT, ctx context.Context, mhKey multihash.Multihash, prefixLen int) ([]ps.PeerInfo, error)

func FindPointersAsync

func FindPointersAsync(dht *routing.IpfsDHT, ctx context.Context, mhKey multihash.Multihash, prefixLen int) <-chan ps.PeerInfo

func GetPointersFromPeer

func GetPointersFromPeer(node *core.IpfsNode, ctx context.Context, p peer.ID, key *cid.Cid) ([]*ps.PeerInfo, error)

func PublishPointer

func PublishPointer(node *core.IpfsNode, ctx context.Context, pointer Pointer) error

func PutPointerToPeer

func PutPointerToPeer(node *core.IpfsNode, ctx context.Context, peer peer.ID, pointer Pointer) error

Types

type Block

type Block struct {
	Id                   string    `json:"id"`
	Date                 time.Time `json:"date"`
	Parents              []string  `json:"parents"`
	ThreadId             string    `json:"thread_id"`
	AuthorPk             string    `json:"author_pk"`
	AuthorUsernameCipher []byte    `json:"author_username_cipher"`
	Type                 BlockType `json:"type"`

	DataId             string `json:"data_id"`
	DataKeyCipher      []byte `json:"data_key_cipher"`
	DataCaptionCipher  []byte `json:"data_caption_cipher"`
	DataMetadataCipher []byte `json:"data_metadata_cipher"`
}

type BlockStore

type BlockStore interface {
	Queryable
	Add(block *Block) error
	Get(id string) *Block
	GetByDataId(dataId string) *Block
	List(offset string, limit int, query string) []Block
	Count(query string) int
	Delete(id string) error
	DeleteByThreadId(threadId string) error
}

type BlockType

type BlockType int
const (
	InviteBlock         BlockType = iota // no longer used
	ExternalInviteBlock                  // no longer used
	JoinBlock
	LeaveBlock
	PhotoBlock
	CommentBlock
	LikeBlock

	IgnoreBlock = 200
	MergeBlock  = 201
)

func (BlockType) Description

func (b BlockType) Description() string

type CafeTokens

type CafeTokens struct {
	Access  string    `json:"access"`
	Refresh string    `json:"refresh"`
	Expiry  time.Time `json:"expiry"`
}

type ConfigStore

type ConfigStore interface {
	Init(password string) error
	Configure(created time.Time) error
	GetCreationDate() (time.Time, error)
	IsEncrypted() bool
}

type DataBlockConfig

type DataBlockConfig struct {
	DataId             string `json:"data_id"`
	DataKeyCipher      []byte `json:"data_key_cipher"`
	DataCaptionCipher  []byte `json:"data_caption_cipher"`
	DataMetadataCipher []byte `json:"data_metadata_cipher"`
}

type Datastore

type Datastore interface {
	Config() ConfigStore
	Profile() ProfileStore
	Threads() ThreadStore
	Devices() DeviceStore
	Peers() PeerStore
	Blocks() BlockStore
	Notifications() NotificationStore
	OfflineMessages() OfflineMessageStore
	Pointers() PointerStore
	PinRequests() PinRequestStore
	Ping() error
	Close()
}

type Device

type Device struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

type DeviceStore

type DeviceStore interface {
	Queryable
	Add(device *Device) error
	Get(id string) *Device
	List(query string) []Device
	Count(query string) int
	Delete(id string) error
}

type Migration

type Migration interface {
	Up(repoPath string, dbPassword string, testnet bool) error
	Down(repoPath string, dbPassword string, testnet bool) error
}

type Notification

type Notification struct {
	Id            string           `json:"id"`
	Date          time.Time        `json:"date"`
	ActorId       string           `json:"actor_id"`                 // peer id
	ActorUsername string           `json:"actor_username,omitempty"` // peer username
	Subject       string           `json:"subject"`                  // thread name | device name
	SubjectId     string           `json:"subject_id"`               // thread id | device id
	BlockId       string           `json:"block_id,omitempty"`       // block id
	DataId        string           `json:"data_id,omitempty"`        // photo id, etc.
	Type          NotificationType `json:"type"`
	Body          string           `json:"body"`
	Read          bool             `json:"read"`
}

type NotificationStore

type NotificationStore interface {
	Queryable
	Add(notification *Notification) error
	Get(id string) *Notification
	Read(id string) error
	ReadAll() error
	List(offset string, limit int, query string) []Notification
	CountUnread() int
	Delete(id string) error
	DeleteByActorId(actorId string) error
	DeleteBySubjectId(subjectId string) error
	DeleteByBlockId(blockId string) error
}

type NotificationType

type NotificationType int
const (
	ReceivedInviteNotification NotificationType = iota // peerA invited you
	DeviceAddedNotification                            // new device added
	PhotoAddedNotification                             // peerA added a photo
	CommentAddedNotification                           // peerA commented on peerB's photo, video, comment, etc.
	LikeAddedNotification                              // peerA liked peerB's photo, video, comment, etc.
	PeerJoinedNotification                             // peerA joined
	PeerLeftNotification                               // peerA left
	TextAddedNotification                              // peerA added a message
)

func (NotificationType) Description

func (n NotificationType) Description() string

type OfflineMessageStore

type OfflineMessageStore interface {
	Queryable
	Put(url string) error
	Has(url string) bool
	SetMessage(url string, message []byte) error
	GetMessages() (map[string][]byte, error)
	DeleteMessage(url string) error
}

type Peer

type Peer struct {
	Row      string `json:"row"`
	Id       string `json:"id"`
	PubKey   []byte `json:"pk"`
	ThreadId string `json:"thread_id"`
}

type PeerStore

type PeerStore interface {
	Queryable
	Add(peer *Peer) error
	Get(row string) *Peer
	GetById(id string) *Peer
	List(offset string, limit int, query string) []Peer
	Count(query string, distinct bool) int
	Delete(id string, thread string) error
	DeleteByThreadId(thread string) error
}

type PinRequest

type PinRequest struct {
	Id   string    `json:"id"`
	Date time.Time `json:"date"`
}

type PinRequestStore

type PinRequestStore interface {
	Queryable
	Put(pr *PinRequest) error
	List(offset string, limit int) []PinRequest
	Delete(id string) error
}

type Pointer

type Pointer struct {
	Cid      *cid.Cid
	Value    ps.PeerInfo
	Purpose  Purpose
	Date     time.Time
	CancelId *peer.ID
}

A pointer is a custom provider inserted into the DHT which points to a location of a file.

For offline messaging purposes we use a hash of the recipient's ID as the key and set the
provider to the location of the ciphertext. We set the Peer ID of the provider object to
a magic number so we distinguish it from regular providers and use a longer ttl.
Note this will only be compatible with the OpenBazaar/go-ipfs fork.

func NewPointer

func NewPointer(mhKey multihash.Multihash, prefixLen int, addr ma.Multiaddr, entropy []byte) (Pointer, error)

entropy is a sequence of bytes that should be deterministic based on the content of the pointer it is hashed and used to fill the remaining 20 bytes of the magic id

type PointerStore

type PointerStore interface {
	Queryable
	Put(p Pointer) error
	Delete(id peer.ID) error
	DeleteAll(purpose Purpose) error
	Get(id peer.ID) *Pointer
	GetByPurpose(purpose Purpose) ([]Pointer, error)
	GetAll() ([]Pointer, error)
}

type ProfileStore

type ProfileStore interface {
	SignIn(username string, tokens *CafeTokens) error
	SignOut() error
	GetUsername() (*string, error)
	SetAvatarId(id string) error
	GetAvatarId() (*string, error)
	GetTokens() (tokens *CafeTokens, err error)
	UpdateTokens(tokens *CafeTokens) error
}

type Purpose

type Purpose int
const (
	MESSAGE   Purpose = 1
	MODERATOR Purpose = 2
	TAG       Purpose = 3
	CHANNEL   Purpose = 4
)

type Queryable

type Queryable interface {
	BeginTransaction() (*sql.Tx, error)
	PrepareQuery(string) (*sql.Stmt, error)
	PrepareAndExecuteQuery(string, ...interface{}) (*sql.Rows, error)
	ExecuteQuery(string, ...interface{}) (sql.Result, error)
}

type Thread

type Thread struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	PrivKey []byte `json:"sk"`
	Head    string `json:"head"`
}

type ThreadStore

type ThreadStore interface {
	Queryable
	Add(thread *Thread) error
	Get(id string) *Thread
	List(query string) []Thread
	Count(query string) int
	UpdateHead(id string, head string) error
	Delete(id string) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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