helper

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostStorePrefix       = "/hosts/"        // from btfs-hub
	HostStorageInfoPrefix = "/host_storage/" // self or from network
)
View Source
const (
	Text = iota + 1
	Base64
)
View Source
const (
	// Normally each op has its own timeout, but in case of buggy paths
	// this timeout serves as a catch-all to prevent mem leaks
	DefaultStorageTimeout = 5 * time.Minute
)

Variables

Functions

func BytesToString

func BytesToString(data []byte, encoding int) (string, error)

func Call

func Call(ctx context.Context, cfg *config.Config, sub string) error

func CheckAndGetReedSolomonShardHashes

func CheckAndGetReedSolomonShardHashes(ctx context.Context, node *core.IpfsNode,
	api coreiface.CoreAPI, rootHash cid.Cid) ([]cid.Cid, int64, error)

CheckAndGetReedSolomonShardHashes checks to see if a root hash is a reed solomon file, if ok, returns the list of shard hashes.

func CheckAndValidateHostStorageMax

func CheckAndValidateHostStorageMax(ctx context.Context, cfgRoot string, r repo.Repo,
	newMax *uint64, maxAllowed bool) (uint64, error)

CheckAndValidateHostStorageMax makes sure the current storage max is under the accepted disk space max, if not, corrects this value. Optionally, this function can take a new max and sets the max to this value. Optionally, maxAllowed enables reducing unreasonable settings down to an allowed value.

func ConvertPubKeyFromString

func ConvertPubKeyFromString(pubKeyStr string) (ic.PubKey, error)

func ConvertToPubKey

func ConvertToPubKey(pubKeyStr string) (ic.PubKey, error)

func GetHostStorageConfig

func GetHostStorageConfig(ctx context.Context, node *core.IpfsNode) (*nodepb.Node_Settings, error)

GetHostStorageConfig checks if locally is storing a config, if yes, returns it, otherwise, queries hub to retrieve the latest default config.

func GetHostStorageConfigForPeer

func GetHostStorageConfigForPeer(node *core.IpfsNode, peerID string) (*nodepb.Node_Settings, error)

GetHostStorageConfigForPeer retrieves locally saved info about peer (including self)

func GetHostStorageConfigHelper

func GetHostStorageConfigHelper(ctx context.Context, node *core.IpfsNode,
	syncHub bool) (*nodepb.Node_Settings, error)

GetHostStorageConfigHelper checks if locally is storing a config, if yes, returns it, otherwise, queries hub to retrieve the latest default config. If syncHub is on, force a sync from Hub to retrieve latest information.

func GetHostStorageKey

func GetHostStorageKey(pid string) ds.Key

func GetHostsFromDatastore

func GetHostsFromDatastore(ctx context.Context, node *core.IpfsNode, mode string, num int) ([]*hubpb.Host, error)

GetHostsFromDatastore retrieves `num` hosts from the datastore, if not enough hosts are available, return an error instead of partial return. When num=0 it means unlimited.

func NewGoContext

func NewGoContext(reqCtx context.Context) (context.Context, context.CancelFunc)

NewGoContext creates a new context with remaining timeout from the existing request context, so that request can be cancelled and new goroutine should use this new context.

func NewKeyHelper

func NewKeyHelper(kss ...string) ds.Key

func PidFromString

func PidFromString(key string) (peer.ID, error)

func PutHostStorageConfig

func PutHostStorageConfig(node *core.IpfsNode, ns *nodepb.Node_Settings) error

PutHostStorageConfig saves an updated storage storage config.

func SaveHostsIntoDatastore

func SaveHostsIntoDatastore(ctx context.Context, node *core.IpfsNode, mode string, nodes []*hubpb.Host) error

SaveHostsIntoDatastore overwrites (removes all existing) hosts and saves the updated hosts according to mode.

func StringToBytes

func StringToBytes(str string, encoding int) ([]byte, error)

Types

type ByteSize

type ByteSize float64
const (
	KB ByteSize = 1 << (10 * iota)
	MB
	GB
	TB
	PB
	EB
	ZB
	YB
)

func (ByteSize) String

func (b ByteSize) String() string

Jump to

Keyboard shortcuts

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