storage

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: MIT Imports: 10 Imported by: 4

Documentation

Overview

Package storage provides the file info storage system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

type Directory struct {
	Name   string
	Size   int64
	Hash   string
	INodes []INode
	// contains filtered or unexported fields
}

func DirectoryFromBytes

func DirectoryFromBytes(data []byte) (*Directory, error)

func NewDirectory

func NewDirectory(name string) *Directory

func (Directory) AddSea

func (d Directory) AddSea(p, name, hash string, sea *FragmentSea) error

Add Fragment stored sea

func (*Directory) CreateDirectory

func (d *Directory) CreateDirectory(p string) (*Directory, error)

Target directories recursively If there is the same Name file exists, it will return error. Else, it will return the pointer of the determination directory INode.

func (*Directory) CreateFile

func (d *Directory) CreateFile(p, name, hash, keyHash string, size int64, fragments []*Fragment) error

Store the file into the path.

func (*Directory) DeleteDirectory

func (d *Directory) DeleteDirectory(p, name string, userOrGroup, shared bool) (seaOperations map[string][]*sea.Operation, keyUsed map[string]int, err error)

Delete iNode of the directory finding by the path.

func (*Directory) DeleteDirectoryKey

func (d *Directory) DeleteDirectoryKey() map[string]int

Delete directory Key.

func (*Directory) DeleteFile

func (d *Directory) DeleteFile(p, name string, userOrGroup, shared bool) (map[string][]*sea.Operation, string, error)

Delete the file finding by the Name under the path.

func (*Directory) GenerateSeaOperations

func (d *Directory) GenerateSeaOperations(action uint, shared bool) map[string][]*sea.Operation

func (*Directory) GetHash

func (d *Directory) GetHash() string

func (*Directory) GetKeys

func (d *Directory) GetKeys() []string

func (*Directory) GetName

func (d *Directory) GetName() string

func (*Directory) GetSize

func (d *Directory) GetSize() int64

func (*Directory) List

func (d *Directory) List(p string) ([]INodeInfo, error)

List information of INodes in the path.

func (*Directory) Move

func (d *Directory) Move(p, name, newPath string) error

Move File or Directory to new path

func (*Directory) ToBytes

func (d *Directory) ToBytes() []byte

func (*Directory) ToJson

func (d *Directory) ToJson() string

func (*Directory) UpdateFileData

func (d *Directory) UpdateFileData(p, name, hash string, size int64, fragments []*Fragment, userOrGroup, shared bool) (map[string][]*sea.Operation, error)

Update the data of file finding by the filename and the path of file.

func (*Directory) UpdateFileKey

func (d *Directory) UpdateFileKey(p, name, keyIndex, hash string, size int64, fragments []*Fragment, userOrGroup, shared bool) (map[string]int, map[string][]*sea.Operation, error)

Update the Key of file

func (*Directory) UpdateName

func (d *Directory) UpdateName(p, name, newName string) error

Update the Name of directory finding by the path.

type File

type File struct {
	Name      string
	Size      int64
	Hash      string
	KeyIndex  string
	Fragments []*Fragment
	// contains filtered or unexported fields
}

func FileFromBytes

func FileFromBytes(data []byte) (*File, error)

func NewFile

func NewFile(name string, size int64, hash string, key string, fragments []*Fragment) *File

func (*File) GenerateSeaOperations

func (f *File) GenerateSeaOperations(action uint, shared bool) map[string][]*sea.Operation

func (*File) GetHash

func (f *File) GetHash() string

func (*File) GetKeys

func (f *File) GetKeys() []string

func (*File) GetName

func (f *File) GetName() string

func (*File) GetSize

func (f *File) GetSize() int64

func (*File) ToBytes

func (f *File) ToBytes() []byte

func (*File) ToJson

func (f *File) ToJson() string

type FileInfo

type FileInfo struct {
	Name      string
	Size      int64
	Hash      string
	Key       string
	Fragments []*Fragment
}

FileInfo is the information of files for usage.

func NewFileInfo

func NewFileInfo(name string, size int64, hash string, key string, fragments []*Fragment) *FileInfo

NewFileInfo is the construct for FileInfo.

type FileKey

type FileKey struct {
	Index     string
	Used      int
	Key       string
	Published bool
}

FileKey store the information of key used to encrypt file.

type FileKeyMap

type FileKeyMap struct {
	Keys []*FileKey
}

FileKeyMap provides file keys manage.

func NewFileKeyMap

func NewFileKeyMap() *FileKeyMap

NewFileKeyMap is the construct for FileKeyMap.

func (*FileKeyMap) AddKey

func (fkm *FileKeyMap) AddKey(key string, used bool) string

AddKey add new information of key. If used, the used count of key will be 1. Else, it will be 0.

func (*FileKeyMap) GetKey

func (fkm *FileKeyMap) GetKey(index string) *FileKey

GetKey search the FileKey by index. If it exists, it will be return. Else, returns nil.

func (*FileKeyMap) PublishKey

func (fkm *FileKeyMap) PublishKey(publicKey, keyIndex, key string) error

PublishKey check key whether valid and publish it.

func (*FileKeyMap) UpdateKeyUsed

func (fkm *FileKeyMap) UpdateKeyUsed(keyUsed map[string]int)

UpdateKeyUsed update used count of keys by index and count.

type Fragment

type Fragment struct {
	Hash string
	Size int64
	Seas []*FragmentSea
}

func NewFragment

func NewFragment(hash string, seas []*FragmentSea) *Fragment

type FragmentSea

type FragmentSea struct {
	Address   string
	PublicKey string
	Weight    int8
	Timestamp time.Time
}

func NewFragmentSea

func NewFragmentSea(address, publicKey string, timestamp time.Time) *FragmentSea

type INode

type INode interface {
	GetName() string
	GetSize() int64
	GetHash() string
	GenerateSeaOperations(action uint, shared bool) map[string][]*sea.Operation
	GetKeys() []string
	ToBytes() []byte
	ToJson() string
	// contains filtered or unexported methods
}

type INodeInfo

type INodeInfo struct {
	IsDir bool
	Name  string
	Size  int64
}

type Root

type Root struct {
	Home   *Directory
	Shared *Directory
	Keys   *FileKeyMap
}

Root store information of files and Keys used to encryption. Store the information of private files in 'Home' directory. Store the information of shared files in 'Shared' directory.

func GenerateRoot

func GenerateRoot() *Root

GenerateRoot generate new root for usage.

func NewRoot

func NewRoot(home, share *Directory, keyMap *FileKeyMap) *Root

NewRoot is the construct for Root.

func RootFromBytes

func RootFromBytes(data []byte) (*Root, error)

RootFromBytes convert root from byte slice.

func (*Root) AddSea

func (root *Root) AddSea(p, name, hash string, sea *FragmentSea) error

AddSea add fragment stored sea's information to its file.

func (*Root) CreateDirectory

func (root *Root) CreateDirectory(p string) error

CreateDirectory create directory in the path.

func (*Root) CreateFile

func (root *Root) CreateFile(p string, info FileInfo) error

CreateFile generate file in the path and store its information.

func (*Root) DeleteDirectory

func (root *Root) DeleteDirectory(p, name string, userOrGroup bool) (map[string][]*sea.Operation, error)

DeleteDirectory delete directory and files in it.

func (*Root) DeleteFile

func (root *Root) DeleteFile(p, name string, userOrGroup bool) (map[string][]*sea.Operation, error)

DeleteFile delete file in the path.

func (*Root) GetDirectory

func (root *Root) GetDirectory(p string) (dir *Directory, err error)

GetDirectory returns the information of directory.

func (*Root) GetFile

func (root *Root) GetFile(p, name string) (file FileInfo, err error)

GetFile returns the information of file.

func (*Root) GetINode

func (root *Root) GetINode(p, name string) (INode, error)

GetINode returns the information of iNode.

func (*Root) GetSharedDirectory

func (root *Root) GetSharedDirectory(p string) (dir *Directory, err error)

GetSharedDirectory returns the information of directory in the 'shared' directory.

func (*Root) GetSharedFile

func (root *Root) GetSharedFile(p, name string) (file FileInfo, err error)

GetSharedFile returns the information of file in the 'shared' directory.

func (*Root) GetSharedINode

func (root *Root) GetSharedINode(p, name string) (INode, error)

GetSharedINode returns the information of iNode in the 'shared' directory.

func (*Root) ListDirectory

func (root *Root) ListDirectory(p string) (iNodes []INodeInfo, err error)

ListDirectory list the information of iNodes in the directory.

func (*Root) ListSharedDirectory

func (root *Root) ListSharedDirectory(p string) (iNodes []INodeInfo, err error)

ListSharedDirectory list the information of iNodes in the 'shared' directory.

func (*Root) Move

func (root *Root) Move(p, name, newPath string) error

Move change the iNode parent path to new path.

func (*Root) PublishKey

func (root *Root) PublishKey(publicKey, keyIndex, key string) error

PublishKey publish the key encrypted by public key.

func (*Root) ShareFiles

func (root *Root) ShareFiles(p, name, dst string, userOrGroup bool) (map[string][]*sea.Operation, []string, error)

ShareFiles copy the information of file to 'shared' directory.

func (*Root) ToBytes

func (root *Root) ToBytes() []byte

ToBytes convert root to byte slice.

func (*Root) UpdateFileData

func (root *Root) UpdateFileData(p string, info FileInfo, userOrGroup bool) (map[string][]*sea.Operation, error)

UpdateFileData change the information of file.

func (*Root) UpdateFileKey

func (root *Root) UpdateFileKey(p string, info FileInfo, userOrGroup bool) (map[string][]*sea.Operation, error)

UpdateFileKey change the encryption key of file and its information.

func (*Root) UpdateName

func (root *Root) UpdateName(p, name, newName string) error

UpdateName change the target iNode's name to new name.

Jump to

Keyboard shortcuts

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