db

package
v0.0.0-...-cffa139 Latest Latest
Warning

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

Go to latest
Published: May 29, 2015 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package db contains a database abstraction layer.

Index

Constants

View Source
const VolumeIDLen = 64

Variables

View Source
var (
	ErrPeerNotFound      = errors.New("peer not found")
	ErrNoStorageForPeer  = errors.New("no storage offered to peer")
	ErrNoLocationForPeer = errors.New("no network location known for peer")
)
View Source
var (
	ErrSharingKeyNameInvalid = errors.New("invalid sharing key name")
	ErrSharingKeyNotFound    = errors.New("sharing key not found")
	ErrSharingKeyExist       = errors.New("sharing key exists already")
)
View Source
var (
	ErrVolNameInvalid     = errors.New("invalid volume name")
	ErrVolNameNotFound    = errors.New("volume name not found")
	ErrVolNameExist       = errors.New("volume name exists already")
	ErrVolumeIDNotFound   = errors.New("volume ID not found")
	ErrVolumeStorageExist = errors.New("volume storage name exists already")
)

Functions

This section is empty.

Types

type DB

type DB struct {
	*bolt.DB
}

DB provides abstracted access to the Bolt database used by the server.

func Open

func Open(path string, mode os.FileMode, options *bolt.Options) (*DB, error)

func (*DB) Update

func (db *DB) Update(fn func(*Tx) error) error

Update makes changes to the database. There can be only one Update call at a time.

If a lock L is held while calling db.Update, L must never be taken inside a write transaction, at the risk of a deadlock.

func (*DB) View

func (db *DB) View(fn func(*Tx) error) error

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

func (*Peer) ID

func (p *Peer) ID() peer.ID

func (*Peer) Locations

func (p *Peer) Locations() *PeerLocations

func (*Peer) Pub

func (p *Peer) Pub() *peer.PublicKey

func (*Peer) Storage

func (p *Peer) Storage() *PeerStorage

type PeerLocations

type PeerLocations struct {
	// contains filtered or unexported fields
}

func (*PeerLocations) Get

func (p *PeerLocations) Get() (addr string, err error)

Get an address to try, to connect to the peer.

Returned addr is valid after the transaction.

TODO support multiple addresses to attempt, with some idea of preferring recent ones.

func (*PeerLocations) Set

func (p *PeerLocations) Set(addr string) error

Set the network location where the peer can be contacted.

TODO support multiple addresses to attempt, with some idea of preferring recent ones.

type PeerStorage

type PeerStorage struct {
	// contains filtered or unexported fields
}

func (*PeerStorage) Allow

func (p *PeerStorage) Allow(backend string) error

func (*PeerStorage) Open

func (p *PeerStorage) Open(opener func(string) (kv.KV, error)) (kv.KV, error)

Open key-value stores as allowed for this peer. Uses the opener function for the actual open action.

If the peer is not allowed to use any storage, returns ErrNoStorageForPeer.

Returned KV is valid after the transaction. Strings passed to the opener function are valid after the transaction.

type Peers

type Peers struct {
	// contains filtered or unexported fields
}

func (*Peers) Get

func (b *Peers) Get(pub *peer.PublicKey) (*Peer, error)

Get returns a Peer for the given public key.

If the peer does not exist, returns ErrPeerNotFound.

func (*Peers) Make

func (b *Peers) Make(pub *peer.PublicKey) (*Peer, error)

Make returns a Peer for the given public key, adding it if necessary.

type SharingKey

type SharingKey struct {
	// contains filtered or unexported fields
}

func (*SharingKey) Name

func (s *SharingKey) Name() string

Name returns the name of the sharing key.

Returned value is valid after the transaction.

func (*SharingKey) Secret

func (s *SharingKey) Secret(out *[32]byte)

Secret copies the secret key to out.

out is valid after the transaction.

type SharingKeys

type SharingKeys struct {
	// contains filtered or unexported fields
}

func (*SharingKeys) Add

func (b *SharingKeys) Add(name string, key *[32]byte) (*SharingKey, error)

Add a sharing key.

If name is invalid, returns ErrSharingKeyNameInvalid.

If a sharing key by that name already exists, returns ErrSharingKeyExist.

func (*SharingKeys) Get

func (b *SharingKeys) Get(name string) (*SharingKey, error)

Get a sharing key.

If the sharing key name is not found, returns ErrSharingKeyNotFound.

type Tx

type Tx struct {
	*bolt.Tx
}

Tx is a database transaction.

Unless otherwise stated, any values returned by methods here (and transitively from their methods) are only valid while the transaction is alive. This does not apply to returned error values.

func (*Tx) Peers

func (tx *Tx) Peers() *Peers

func (*Tx) SharingKeys

func (tx *Tx) SharingKeys() *SharingKeys

func (*Tx) Volumes

func (tx *Tx) Volumes() *Volumes

type Volume

type Volume struct {
	// contains filtered or unexported fields
}

func (*Volume) DirBucket

func (v *Volume) DirBucket() *bolt.Bucket

DirBucket returns a bolt bucket for storing directory contents in.

func (*Volume) InodeBucket

func (v *Volume) InodeBucket() *bolt.Bucket

InodeBucket returns a bolt bucket for storing inodes in.

func (*Volume) SnapBucket

func (v *Volume) SnapBucket() *bolt.Bucket

SnapBucket returns a bolt bucket for storing snapshots in.

func (*Volume) Storage

func (v *Volume) Storage() *VolumeStorage

func (*Volume) VolumeID

func (v *Volume) VolumeID(out *VolumeID)

VolumeID copies the volume ID to out.

out is valid after the transaction.

type VolumeID

type VolumeID [VolumeIDLen]byte

type VolumeStorage

type VolumeStorage struct {
	// contains filtered or unexported fields
}

func (*VolumeStorage) Add

func (vs *VolumeStorage) Add(name string, backend string, sharingKey *SharingKey) error

Add a storage backend to be used by the volume.

Active Volume instances are not notified.

If volume has storage by that name already, returns ErrVolumeStorageExist.

func (*VolumeStorage) Cursor

func (vs *VolumeStorage) Cursor() *VolumeStorageCursor

type VolumeStorageCursor

type VolumeStorageCursor struct {
	// contains filtered or unexported fields
}

func (*VolumeStorageCursor) First

func (*VolumeStorageCursor) Next

type VolumeStorageItem

type VolumeStorageItem struct {
	// contains filtered or unexported fields
}

func (*VolumeStorageItem) Backend

func (item *VolumeStorageItem) Backend() (string, error)

Backend returns the storage backend for this item.

Returned value is valid after the transaction.

func (*VolumeStorageItem) SharingKeyName

func (item *VolumeStorageItem) SharingKeyName() (string, error)

SharingKeyName returns the sharing key name for this item.

Returned value is valid after the transaction.

type Volumes

type Volumes struct {
	// contains filtered or unexported fields
}

func (*Volumes) Create

func (b *Volumes) Create(name string, storage string, sharingKey *SharingKey) (*Volume, error)

Create a totally new volume, not yet shared with any peers.

If the name exists already, returns ErrVolNameExist.

func (*Volumes) GetByName

func (b *Volumes) GetByName(name string) (*Volume, error)

func (*Volumes) GetByVolumeID

func (b *Volumes) GetByVolumeID(volID *VolumeID) (*Volume, error)

Directories

Path Synopsis
Package wire is a generated protocol buffer package.
Package wire is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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