repo

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2018 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LockPathSuffix is the suffix appended to each file in its locked state.
	LockPathSuffix = ".locked"
	// LockDirSuffix is the suffix appended to each directory in its locked state.
	LockDirSuffix = ".tgz" + LockPathSuffix
)

Variables

View Source
var (
	// ErrBadPassword is returned by Open() when the decyption password seems to be wrong.
	ErrBadPassword = errors.New("Failed to open repository. Probably wrong password")
)
View Source
var (
	// ErrNoSuchRemote will be returned by various remote functions
	// when a non-existing remote was requested.
	ErrNoSuchRemote = errors.New("No such remote with this name")
)

Functions

func CheckPassword

func CheckPassword(baseFolder, password string) error

CheckPassword will try to validate `password` by decrypting something in `baseFolder`.

func Init

func Init(baseFolder, owner, password, backendName string, daemonPort int64) error

Init will create a new repository on disk at `baseFolder`. `owner` will be the new owner and should be something like user@domain/resource. `backendName` is the name of the backend, either "ipfs" or "mock". `daemonPort` is the port of the local daemon.

func LockRepo

func LockRepo(root, user, password string, lockExcludes, unlockExcludes []string) error

LockRepo encrypts all files (except those in `lockExcludes`) in `root`, depending on `user` and `password`. `unlockExcludes` is only used to prevent warnings about not locked files.

func UnlockRepo

func UnlockRepo(root, user, password string, lockExcludes, unlockExcludes []string) error

UnlockRepo is the exact opposite of LockRepo.

Types

type Backend

type Backend interface {
	GC() ([]h.Hash, error)
}

Backend defines the method needed from the underlying storage backend to create & manage a repository.

type Folder

type Folder struct {
	Folder string
}

Folder defines a folder setting of the remote.

type Keyring

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

Keyring manages our own keypair and stores the last known pubkeys of other remotes.

func (*Keyring) Decrypt

func (kp *Keyring) Decrypt(data []byte) ([]byte, error)

Decrypt decrypts a message encrypted with our public key. This is not an efficient method and is not supposed to be used for large amounts of data.

func (*Keyring) Encrypt

func (kp *Keyring) Encrypt(data, pubKey []byte) ([]byte, error)

Encrypt `data` with `pubKey`. If it's desired to encrypt a message with our own pubkey, then use the PubKeyBytes() method to load one. This is not an efficient method and is not supposed to be used for large amounts of data.

func (*Keyring) OwnPubKey

func (kp *Keyring) OwnPubKey() ([]byte, error)

OwnPubKey returns an exported version of our own public key.

func (*Keyring) PubKeyFor

func (kp *Keyring) PubKeyFor(name string) ([]byte, error)

PubKeyFor returns the stored public key for a partner named `name`

func (*Keyring) SavePubKey

func (kp *Keyring) SavePubKey(name string, pubKey []byte) error

SavePubKey stores a public key from a partner with the name `name`

type Remote

type Remote struct {
	// Name is the name of the remote.
	// This name can be freely chosen.
	Name string

	// Folders is a list of folders the remote has access to.
	// If this list is empty, this remote may access all folders.
	Folders []Folder

	// Fingerprint is the fingerprint of the remote.
	Fingerprint peer.Fingerprint
}

Remote is one entry in the remote list. It defines what users we may talk to (and also how)

type RemoteList

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

RemoteList is a helper that parses the remote access yml file and makes it easily accessible from the Go side.

func NewRemotes

func NewRemotes(path string) (*RemoteList, error)

NewRemotes returns a new RemoteList.

func (*RemoteList) AddOrUpdateRemote added in v0.2.0

func (rl *RemoteList) AddOrUpdateRemote(remote Remote) error

AddOrUpdateRemote will add/update a remote.

func (*RemoteList) Clear

func (rl *RemoteList) Clear() error

Clear will remove all of the remote list.

func (*RemoteList) Export

func (rl *RemoteList) Export(w io.Writer) error

Export writes the contents of the remote list to `w` in YAML format.

func (*RemoteList) ListRemotes

func (rl *RemoteList) ListRemotes() ([]Remote, error)

ListRemotes will return a copy of the remote list entries.

func (*RemoteList) Remote

func (rl *RemoteList) Remote(name string) (Remote, error)

Remote will return the remote named `name`. If there is not such remote, ErrNoSuchRemote is returned.

func (*RemoteList) RmRemote

func (rl *RemoteList) RmRemote(name string) error

RmRemote will remove a remote by `name`. If there is not such remote, ErrNoSuchRemote is returned.

func (*RemoteList) SaveList

func (rl *RemoteList) SaveList(remotes []Remote) error

SaveList will store the contents of `remotes` to disk.

type Repository

type Repository struct {

	// Absolute path to the repository root
	BaseFolder string

	// Name of the owner of this repository
	Owner string

	// Config interface
	Config *config.Config

	// Remotes gives access to all known remotes
	Remotes *RemoteList
	// contains filtered or unexported fields
}

Repository provides access to the file structure of a single repository.

Informal: This file structure currently looks like this: config.yml OWNER BACKEND REPO_ID remotes.yml data/

<backend_name>
    (data-backend specific)

metadata/

<name_1>
    (fs-backend specific)
<name_2>
    (fs-backend specific)

func Open

func Open(baseFolder, password string) (*Repository, error)

Open will open the repository at `baseFolder` by using `password`.

func (*Repository) BackendName

func (rp *Repository) BackendName() string

BackendName returns the backend name used when constructing the repo.

func (*Repository) BackendPath

func (rp *Repository) BackendPath(name string) string

BackendPath returns the absolute path to the backend folder inside the repo.

func (*Repository) Close

func (rp *Repository) Close(password string) error

Close will lock the repository, making this instance unusable.

func (*Repository) CurrentUser

func (rp *Repository) CurrentUser() string

CurrentUser returns the current user of the repository. (i.e. what FS is being shown)

func (*Repository) FS

func (rp *Repository) FS(owner string, bk catfs.FsBackend) (*catfs.FS, error)

FS returns a filesystem for `owner`. If there is none yet, it will create own associated to the respective owner.

func (*Repository) GC

func (rp *Repository) GC(backend Backend, aggressive bool) (map[string]map[string]h.Hash, error)

GC runs the garbage collector of the backend. If `aggressive` is true, also the internal data structures will be garbage collected, which might lead to minimally less storage. It returns a map of maps, where the inner map consists of content hash58 to binary representation of the same hash. The outer key is the owner of the file.

func (*Repository) HaveFS

func (rp *Repository) HaveFS(owner string) bool

HaveFS will return true if we have data for a certain owner.

func (*Repository) Keyring

func (rp *Repository) Keyring() *Keyring

Keyring returns the keyring of the repository.

func (*Repository) RepoID added in v0.2.0

func (rp *Repository) RepoID() (string, error)

RepoID returns a unique ID specific to this repository.

func (*Repository) SaveConfig added in v0.2.0

func (rp *Repository) SaveConfig() error

SaveConfig dumps the in memory config to disk.

func (*Repository) SetCurrentUser

func (rp *Repository) SetCurrentUser(user string)

SetCurrentUser sets the current user of the repository. (i.e. called by "become" when changing the FS)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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