library

package
v0.0.0-...-8027ee6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 14 Imported by: 1

README

Library API

The library API allows to share documents with other nodes in the decentralized network. Like for usual data repository (e.g. Sharepoint)

The API

    func Get(p *pool.Pool, channel string) Library

    func (l *Library) List(folder string) ([]Document, error)   
    func (l *Library) Send(localPath string, name string, tags ...string) (pool.Head, error)
    func (l *Library) Receive(id uint64, localPath string, tags ...string) (pool.Head, error)
    func (l *Library) Delete(id uint64) error
    func (l *Library) Save(id uint64, dest string) error


    func (l *Library) GetLocalPath(name string) (string, bool) 
    func (l *Library) GetLocalDocument(name string) (Document, bool) 

The life cycle

Let's consider a simple pool with only two nodes, Alice and Bob. Alice works on a document Hello.doc with Bob.

# Action Alice Disk Alice State Bob Disk Bob State Pool
1 Alice creates a file hello.doc - - - -
2 Alice sends to the pool hello.doc Sync - Update hello.doc
3 Bob receives from the pool hello.doc Sync - Sync hello.doc
4 Alice deletes the file - Deleted - Sync hello.doc
5 Bop edit the file - Deleted - Modified hello.doc
6 Bop sends to the pool - Update - Sync hello.doc
7 Alice receives the file hello.doc Sync - Sync hello.doc
8 Alice edit the file hello.doc Modified - Update hello.doc

The state represents the condition of the local file compared with the file with the same name on the pool State is computed by comparing

State Condition (local) Condition (remote)
Sync Same mod times Same Hash
Modified Newer on disk
Updated Older on disk Hash is contained
Conflict Hash mismatch
Deleted File does not exist

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Auto = ""
View Source
var HashChainMaxLength = 128

Functions

This section is empty.

Types

type Document

type Document struct {
	Name      string    `json:"name"`
	AuthorId  string    `json:"authorId"`
	LocalPath string    `json:"localPath"`
	Id        uint64    `json:"id"`
	ModTime   time.Time `json:"modTime"`
	State     State     `json:"state"`
	Hash      []byte    `json:"hash"`
	HashChain [][]byte  `json:"hashChain"`
	Versions  []Version `json:"versions"`
}

type File

type File struct {
	Name        string    `json:"name"`
	Id          uint64    `json:"id"`
	ModTime     time.Time `json:"modTime"`
	Size        uint64    `json:"size"`
	AuthorId    string    `json:"authorId"`
	ContentType string    `json:"contentType"`
	Hash        []byte    `json:"hash"`
	HashChain   [][]byte  `json:"hashChain"`
	Tags        []string  `json:"tags"`
	CTime       int64
}

File includes information about a file stored on the library. Most information refers on the synchronized state with the exchange.

type Library

type Library struct {
	Pool *pool.Pool
	Name string
}

func Get

func Get(p *pool.Pool, name string) Library

Get returns a library app mounted on the provided path in the pool

func (*Library) Delete

func (l *Library) Delete(id uint64) error

func (*Library) Find

func (l *Library) Find(id uint64) (File, error)

func (*Library) GetLocalPath

func (l *Library) GetLocalPath(name string) (string, bool)

func (*Library) List

func (l *Library) List(folder string) (List, error)

List returns the documents in provided folder

func (*Library) Receive

func (l *Library) Receive(id uint64, localPath string) (File, error)

func (*Library) Reset

func (l *Library) Reset() error

Reset removes all the local content

func (*Library) Save

func (l *Library) Save(id uint64, dest string) error

func (*Library) Send

func (l *Library) Send(localPath string, name string, solveConflicts bool, tags ...string) (File, error)

Send uploads the specified file localPath to the pool with the provided name. When solveConflicts is true the

type List

type List struct {
	Folder     string     `json:"folder"`
	Documents  []Document `json:"documents"`
	Subfolders []string   `json:"subfolders"`
}

type Local

type Local struct {
	Id        uint64    `json:"id"`
	Name      string    `json:"name"`
	Path      string    `json:"path"`
	AuthorId  string    `json:"authorId"`
	ModTime   time.Time `json:"modTime"`
	Size      uint64    `json:"size"`
	Hash      []byte    `json:"hash"`
	HashChain [][]byte  `json:"hashChain"`
}

type State

type State int
const (
	Sync State = 1 << iota
	Updated
	Modified
	Deleted
	Conflict
	New
)

type Version

type Version struct {
	AuthorId    string    `json:"authorId"`
	State       State     `json:"state"`
	Size        uint64    `json:"size"`
	ModTime     time.Time `json:"modTime"`
	ContentType string    `json:"contentType"`
	Hash        []byte    `json:"hash"`
	Tags        []string  `json:"tags"`
	Id          uint64    `json:"id"`
}

Jump to

Keyboard shortcuts

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