util

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const COMMIT_ENDPOINT = "/v1/connection/commit/"
View Source
const CONNECTION_ENDPOINT = "/v1/connection/details/"
View Source
const DOWNLOAD_ENDPOINT = "/v1/file/download/"
View Source
const FILE_META_ENDPOINT = "/v1/file/meta/"
View Source
const FILE_STATS_ENDPOINT = "/v1/file/stats/"
View Source
const LATEST_READ_MARKER = "/v1/readmarker/latest"
View Source
const LIST_ENDPOINT = "/v1/file/list/"
View Source
const UPLOAD_ENDPOINT = "/v1/file/upload/"

Variables

View Source
var (
	FILEEXISTS = errors.New("File already exists")
)

Functions

func CalculateDirHash

func CalculateDirHash(d *FileDirInfo) string

func DeleteFile

func DeleteFile(d *FileDirInfo, path string) error

func GetBlobberJson

func GetBlobberJson(b *Blobber) string

func GetFileContentType

func GetFileContentType(out *os.File) (string, error)

func GetJsonFromDirTree

func GetJsonFromDirTree(d *FileDirInfo) string

func Hash

func Hash(text string) string

Hash - the hashing used for the merkle tree construction

func HashStringToBytes

func HashStringToBytes(hash string) []byte

HashStringToBytes - convert a hex hash string to bytes

func MHash

func MHash(h1 string, h2 string) string

MHash - merkle hashing of a pair of child hashes

func NewCommitRequest

func NewCommitRequest(baseUrl, allocation string, client ClientConfig, body io.Reader) (*http.Request, error)

func NewConnectionId

func NewConnectionId() int64

func NewDeleteRequest

func NewDeleteRequest(baseUrl, allocation string, client ClientConfig, body io.Reader) (*http.Request, error)

func NewDownloadRequest

func NewDownloadRequest(baseUrl, allocation string, client ClientConfig, body io.Reader) (*http.Request, error)

func NewFileMetaRequest

func NewFileMetaRequest(baseUrl string, allocation string, client ClientConfig, body io.Reader) (*http.Request, error)

func NewLatestReadMarkerRequest

func NewLatestReadMarkerRequest(baseUrl string, client ClientConfig) (*http.Request, error)

func NewListRequest

func NewListRequest(baseUrl, allocation string, client ClientConfig, path string) (*http.Request, error)

func NewStatsRequest

func NewStatsRequest(baseUrl, allocation string, client ClientConfig, path string) (*http.Request, error)

func NewUploadRequest

func NewUploadRequest(baseUrl, allocation string, client ClientConfig, body io.Reader, update bool) (*http.Request, error)

func Now

func Now() int64

Now - current datetime

func SetBlobberDirTree

func SetBlobberDirTree(b *Blobber, j string) error

func ToHex

func ToHex(buf []byte) string

ToHex - converts a byte array to hex encoding with upper case

func VerifyMerklePath

func VerifyMerklePath(hash string, path *MTPath, root string) bool

Types

type Blobber

type Blobber struct {
	Id          string      `json:"id"`
	UrlRoot     string      `json:"url"`
	ReadCounter int64       `json:"counter"`
	DirTree     FileDirInfo `json:"tree,omit_empty"`
	ConnObj     Connection  `json:"-"`
}

func GetBlobbers

func GetBlobbers(j string) ([]Blobber, error)

type ClientConfig

type ClientConfig struct {
	Id         string `json:"id"`
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
}

func GetClientConfig

func GetClientConfig(j string) (ClientConfig, error)

type Connection

type Connection struct {
	ConnectionId int64
	DirTree      FileDirInfo
	// contains filtered or unexported fields
}

func (*Connection) AddFile

func (c *Connection) AddFile(path, hash string, size int64) error

func (*Connection) DeleteFile

func (c *Connection) DeleteFile(path string, size int64) error

func (*Connection) GetAllocationRoot

func (c *Connection) GetAllocationRoot(timestamp int64) string

func (*Connection) GetCommitData

func (c *Connection) GetCommitData() string

func (*Connection) GetSize

func (c *Connection) GetSize() int64

func (*Connection) Reset

func (c *Connection) Reset()

func (*Connection) UpdateFile

func (c *Connection) UpdateFile(path, hash string, size int64) error

type DeleteToken

type DeleteToken struct {
	FilePathHash string `json:"file_path_hash"`
	FileRefHash  string `json:"file_ref_hash"`
	AllocationID string `json:"allocation_id"`
	Size         int64  `json:"size"`
	BlobberID    string `json:"blobber_id"`
	Timestamp    int64  `json:"timestamp"`
	ClientID     string `json:"client_id"`
	Signature    string `json:"signature"`
	Status       int    `json:"status"`
}

func NewDeleteToken

func NewDeleteToken() *DeleteToken

func (*DeleteToken) GetHash

func (dt *DeleteToken) GetHash() string

func (*DeleteToken) Sign

func (dt *DeleteToken) Sign(privateKey string) error

type FileConfig

type FileConfig struct {
	Name       string `json:"Name"`
	Path       string `json:"Path"`
	Size       int64  `json:"Size"`
	Type       string `json:"Type"`
	ActualHash string
	FileHash   hash.Hash
	FileHashWr io.Writer
	Remaining  int64
}

func GetFileConfig

func GetFileConfig(j string) (FileConfig, error)

type FileDirInfo

type FileDirInfo struct {
	Type     string                 `json:"type"`
	Name     string                 `json:"name"`
	Hash     string                 `json:"hash"`
	Size     int64                  `json:"size,omit_empty"`
	Meta     map[string]interface{} `json:"meta_data",omit_empty`
	Children []FileDirInfo          `json:"children,omit_empty"`
}

func AddDir

func AddDir(d *FileDirInfo, path string) *FileDirInfo

func GetDirTreeFromJson

func GetDirTreeFromJson(j string) (FileDirInfo, error)

func GetFileInfo

func GetFileInfo(d *FileDirInfo, path string) *FileDirInfo

func InsertFile

func InsertFile(d *FileDirInfo, path, hash string, size int64) (*FileDirInfo, error)

func ListDir

func ListDir(d *FileDirInfo, path string) []FileDirInfo

func NewDirTree

func NewDirTree() FileDirInfo

func (*FileDirInfo) GetInfoHash

func (fi *FileDirInfo) GetInfoHash() string

type Hashable

type Hashable interface {
	GetHash() string
	GetHashBytes() []byte
}

Hashable - anything that can provide it's hash

type MTPath

type MTPath struct {
	Nodes     []string `json:"nodes"`
	LeafIndex int      `json:"leaf_index"`
}

MTPath - The merkle tree path

type MarkerI

type MarkerI interface {
	GetHash() string
	Sign(privateKey string) error
}

type MerkleTree

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

MerkleTree - A data structure that implements MerkleTreeI interface

func (*MerkleTree) ComputeTree

func (mt *MerkleTree) ComputeTree(hashes []Hashable)

ComputeTree - given the leaf nodes, compute the merkle tree

func (*MerkleTree) GetLeafIndex

func (mt *MerkleTree) GetLeafIndex(hash Hashable) int

GetLeafIndex - Get the index of the leaf node in the tree

func (*MerkleTree) GetPath

func (mt *MerkleTree) GetPath(hash Hashable) *MTPath

GetPath - get the path that can be used to verify the merkle tree

func (*MerkleTree) GetPathByIndex

func (mt *MerkleTree) GetPathByIndex(idx int) *MTPath

GetPathByIndex - get the path of a leaf node at index i

func (*MerkleTree) GetRoot

func (mt *MerkleTree) GetRoot() string

GetRoot - get the root of the merkle tree

func (*MerkleTree) GetTree

func (mt *MerkleTree) GetTree() []string

GetTree - get the entire merkle tree

func (*MerkleTree) SetTree

func (mt *MerkleTree) SetTree(leavesCount int, tree []string) error

SetTree - set the entire merkle tree

func (*MerkleTree) VerifyPath

func (mt *MerkleTree) VerifyPath(hash Hashable, path *MTPath) bool

VerifyPath - given a leaf node and the path, verify that the node is part of the tree

type MerkleTreeI

type MerkleTreeI interface {
	//API to create a tree from leaf nodes
	ComputeTree(hashes []Hashable)
	GetRoot() string
	GetTree() []string

	//API to load an existing tree
	SetTree(leavesCount int, tree []string) error

	// API for verification when the leaf node is known
	GetPath(hash Hashable) *MTPath               // Server needs to provide this
	VerifyPath(hash Hashable, path *MTPath) bool //This is only required by a client but useful for testing

	/* API for random verification when the leaf node is uknown
	(verification of the data to hash used as leaf node is outside this API) */
	GetPathByIndex(idx int) *MTPath
}

MerkleTreeI - a merkle tree interface required for constructing and providing verification

type OperationStatus

type OperationStatus struct {
	Path string
	Size int64
}

type ReadMarker

type ReadMarker struct {
	ClientID        string `json:"client_id"`
	ClientPublicKey string `json:"client_public_key"`
	BlobberID       string `json:"blobber_id"`
	AllocationID    string `json:"allocation_id"`
	OwnerID         string `json:"owner_id"`
	Timestamp       int64  `json:"timestamp"`
	ReadCounter     int64  `json:"counter"`
	Signature       string `json:"signature"`
}

func NewReadMarker

func NewReadMarker() *ReadMarker

func (*ReadMarker) GetHash

func (rm *ReadMarker) GetHash() string

func (*ReadMarker) Sign

func (rm *ReadMarker) Sign(privateKey string) error

type SecureSerializableValue

type SecureSerializableValue struct {
	Buffer []byte
}

SecureSerializableValue - a proxy persisted value that just tracks the encoded bytes of a persisted value

func (*SecureSerializableValue) Decode

func (spv *SecureSerializableValue) Decode(buf []byte) error

Decode - implement interface

func (*SecureSerializableValue) Encode

func (spv *SecureSerializableValue) Encode() []byte

Encode - implement interface

func (*SecureSerializableValue) GetHash

func (spv *SecureSerializableValue) GetHash() string

GetHash - implement interface

func (*SecureSerializableValue) GetHashBytes

func (spv *SecureSerializableValue) GetHashBytes() []byte

GetHashBytes - implement interface

type SecureSerializableValueI

type SecureSerializableValueI interface {
	Serializable
	Hashable
}

SecureSerializableValueI an interface that makes a serializable value secure with hashing

type Serializable

type Serializable interface {
	Encode() []byte
	Decode([]byte) error
}

Serializable interface

type StringHashable

type StringHashable struct {
	Hash string
}

func NewStringHashable

func NewStringHashable(hash string) *StringHashable

func (*StringHashable) GetHash

func (sh *StringHashable) GetHash() string

func (*StringHashable) GetHashBytes

func (sh *StringHashable) GetHashBytes() []byte

type WriteMarker

type WriteMarker struct {
	AllocationRoot         string `json:"allocation_root"`
	PreviousAllocationRoot string `json:"prev_allocation_root"`
	AllocationID           string `json:"allocation_id"`
	Size                   int64  `json:"size"`
	BlobberID              string `json:"blobber_id"`
	Timestamp              int64  `json:"timestamp"`
	ClientID               string `json:"client_id"`
	Signature              string `json:"signature"`
}

func NewWriteMarker

func NewWriteMarker() *WriteMarker

func (*WriteMarker) GetHash

func (wm *WriteMarker) GetHash() string

func (*WriteMarker) Sign

func (wm *WriteMarker) Sign(privateKey string) error

Jump to

Keyboard shortcuts

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