lib

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: 35 Imported by: 0

Documentation

Overview

Package lib provides the utilities for project.

Index

Constants

View Source
const (
	ClientCategoryUser = true
	ClientCategorySea  = false
)

The Category of ClientFramework.

View Source
const (

	// FamilyName is the SeaStorage's transaction identity.
	FamilyName string = "SeaStorage"
	// FamilyVersion is the version of SeaStorage's transaction.
	FamilyVersion string = "1.0"
	// DefaultTmpPath is used for storing temp file.
	DefaultTmpPath string = "/tmp/SeaStorage"
	// DefaultWait is the waiting time for batch commits.
	DefaultWait = time.Minute
	// DefaultQueryLimit is the limit of state queries.
	DefaultQueryLimit uint = 20
	// EncryptSuffix is the encrypted file's suffix.
	EncryptSuffix string = ".enc"
	// DefaultConfigFilename is the config filename.
	DefaultConfigFilename string = "config"
	// PackageSize is the limit of each package's max size.
	PackageSize int64 = 128 * 1024 * 1024
	// ContentTypeOctetStream is the content type for request.
	ContentTypeOctetStream string = "application/octet-stream"

	// BatchSubmitAPI is the api for batch submission.
	BatchSubmitAPI string = "batches"
	// BatchStatusAPI is the api for getting batches' status.
	BatchStatusAPI string = "batch_statuses"
	// StateAPI is the api for getting data stored in the blockchain.
	StateAPI string = "state"

	// AESKeySize is the size of AES key.
	AESKeySize int = 256
	// IvSize is the AES-CTR iv's size.
	IvSize = aes.BlockSize
	// BufferSize is the size for encryption.
	BufferSize = 4096
)

Variables

View Source
var (
	// TPURL is the Hyperledger Sawtooth rest api url.
	TPURL string
	// ValidatorURL is the Hyperledger Sawtooth validator tcp url.
	ValidatorURL string
	// StoragePath is the path that provided storage resources by sea.
	StoragePath string
	// StorageSize is the limit size of the storage resources.
	StorageSize int64
	// ListenAddress is the address used for joining P2P network and listening for protobuf.
	ListenAddress string
	// ListenPort is the port for the P2P Network protobuf listener.
	ListenPort int
	// BootstrapAddrs is the addresses in the P2P Network. These addresses are using for node joining P2P Network.
	BootstrapAddrs []ma.Multiaddr
)
View Source
var (
	// Logger provides log function.
	Logger *logrus.Logger
	// DefaultTPURL is the default Hyperledger Sawtooth rest api url.
	DefaultTPURL = "http://101.132.168.252:8008"
	// DefaultValidatorURL is the default Hyperledger Sawtooth validator tcp url.
	DefaultValidatorURL = "tcp://101.132.168.252:4004"
	// DefaultListenAddress is the default listen address for P2P network node.
	DefaultListenAddress = "0.0.0.0"
	// DefaultListenPort is the default listen port for P2P network node.
	DefaultListenPort = 5001
	// PrivateKeyFile is the path of private key.
	PrivateKeyFile string
	// DefaultKeyPath is the default path for key storing.
	DefaultKeyPath string
	// DefaultPrivateKeyFile is the default path of private key.
	DefaultPrivateKeyFile string
	// DefaultConfigPath is the default path for config storing.
	DefaultConfigPath string
	// DefaultLogPath is the default path for log storing.
	DefaultLogPath string
	// DefaultLargeFileSize is the limit of max file size for RS erasure coding using.
	DefaultLargeFileSize int64 = 1024 * 1024 * 1024
	// DefaultDataShards is the number of data shard in RS erasure coding.
	DefaultDataShards = 5
	// DefaultParShards is the number of parity shard in RS erasure coding.
	DefaultParShards = 3
	// DefaultStoragePath is the default path for providing storage resources.
	DefaultStoragePath string
	// DefaultStorageSize is the default limit size of storage resources.
	DefaultStorageSize int64 = 1024 * 1024 * 1024
	// DefaultBootstrapAddrs is the default addresses for joining P2P network.
	DefaultBootstrapAddrs = []string{
		"/ip4/129.204.249.51/tcp/5001/p2p/16Uiu2HAkwxu3JAoqZ7QQ343hQuADCbkqfimCNRTnqQgoUpvoKEty",
		"/ip4/101.132.168.252/tcp/5001/p2p/16Uiu2HAmHoT7LJpqYhZfLddG6Gu7WBkHh44cMiGp1FgCjPjbhEkA",
	}
)

Functions

func Copy

func Copy(srcPath, dstPath string) error

Copy the source file to the destination path.

func GenerateKey

func GenerateKey(keyName string, keyPath string)

GenerateKey generate key pair (Secp256k1) and store them in the storage path.

func GetStateData

func GetStateData(addr string) ([]byte, error)

GetStateData returns the data of the address in byte slice.

func ListAll

func ListAll(start string, limit uint) ([]interface{}, error)

ListAll returns the list of data that address started with the SeaStorage's namespace.

func ListSeas

func ListSeas(start string, limit uint) ([]interface{}, error)

ListSeas returns the list of data that address started with the SeaNamespace.

func ListSeasPublicKey

func ListSeasPublicKey(start string, limit uint) ([]string, error)

ListSeasPublicKey returns the list of sea's public key.

func ListUsers

func ListUsers(start string, limit uint) ([]interface{}, error)

ListUsers returns the list of data that address started with the UserNamespace.

Types

type ClientFramework

type ClientFramework struct {
	Name     string // The name of user or sea.
	Category bool   // The category of client framework.

	State chan []byte
	// contains filtered or unexported fields
}

ClientFramework provides SeaStorage base operations for both user and sea.

func NewClientFramework

func NewClientFramework(name string, category bool, keyFile string) (*ClientFramework, error)

NewClientFramework is the construct for ClientFramework.

func (*ClientFramework) Close

func (cf *ClientFramework) Close()

Close is the deconstruct for ClientFramework.

func (*ClientFramework) DecryptFileKey

func (cf *ClientFramework) DecryptFileKey(key string) ([]byte, error)

DecryptFileKey returns the key decrypted by user's private key. If the error is not nil, it will return.

func (*ClientFramework) GenerateOperation

func (cf *ClientFramework) GenerateOperation(sea, path, name, hash string, size int64) *tpUser.Operation

GenerateOperation return the user operation signed by user's private key.

func (*ClientFramework) GetAddress

func (cf *ClientFramework) GetAddress() string

GetAddress returns the address of user or sea.

func (*ClientFramework) GetData

func (cf *ClientFramework) GetData() ([]byte, error)

GetData returns the data of user or sea.

func (*ClientFramework) GetPublicKey

func (cf *ClientFramework) GetPublicKey() string

GetPublicKey returns the public key of user or sea.

func (*ClientFramework) Register

func (cf *ClientFramework) Register(name string) error

Register user or sea. Create user or sea in the blockchain.

func (*ClientFramework) SendTransaction

func (cf *ClientFramework) SendTransaction(seaStoragePayloads []tpPayload.SeaStoragePayload, inputs, outputs []string) (map[string]interface{}, error)

SendTransaction send transactions by the batch.

func (*ClientFramework) SendTransactionAndWaiting

func (cf *ClientFramework) SendTransactionAndWaiting(seaStoragePayloads []tpPayload.SeaStoragePayload, inputs, outputs []string) error

SendTransactionAndWaiting send transaction by the batch and waiting for the batches committed.

func (*ClientFramework) WaitingForCommitted

func (cf *ClientFramework) WaitingForCommitted() error

WaitingForCommitted wait for batches committed. If timeout or batches invalid, it will return error.

func (*ClientFramework) WatchingForState added in v1.0.1

func (cf *ClientFramework) WatchingForState() error

func (*ClientFramework) Whoami

func (cf *ClientFramework) Whoami()

Whoami display the information of user or sea.

Jump to

Keyboard shortcuts

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