utils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: BSD-3-Clause Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const KLibp2pHost = "libp2p-host"

KLibp2pHost is the datastore key for storing our libp2p identity private key

Variables

View Source
var Chooser = AddDagPBSupportToChooser(func(ipld.Link, ipld.LinkContext) (ipld.NodePrototype, error) {
	return basicnode.Prototype.Any, nil
})

Chooser decides which node type to use when decoding IPLD nodes

View Source
var HAMTHashOption = hamt.UseHashFunction(func(input []byte) []byte {
	res := sha256.Sum256(input)
	return res[:]
})

HAMTHashOption uses 256 hash to prevent collision attacks

View Source
var MimeTypes = map[string]FileType{
	"application": FTApplication,
	"archive":     FTArchive,
	"audio":       FTAudio,
	"video":       FTVideo,
	"image":       FTImage,
	"text":        FTText,
	"chemical":    FTChemical,
	"font":        FTFont,
	"message":     FTMessage,
	"model":       FTModel,
}

Functions

func AddrBytesToAddrInfo

func AddrBytesToAddrInfo(b []byte) (*peer.AddrInfo, error)

AddrBytesToAddrInfo tunrs a compressed address into addrInfo struct

func AddrStringToAddrInfo

func AddrStringToAddrInfo(s string) (*peer.AddrInfo, error)

AddrStringToAddrInfo turns a string address of format /p2p/<addr>/<peerid> to AddrInfo struct

func CodecFromString

func CodecFromString(name string) (uint64, error)

CodecFromString returns a codec code from a string name

func FormatToken

func FormatToken(tok string, tp string) string

FormatToken takes a token type and a token value and creates a string ready to send in the http Authorization header

func Libp2pKey

func Libp2pKey(ks keystore.Keystore) (ci.PrivKey, error)

Libp2pKey gets a libp2p host private key from the keystore if available or generates a new one

func ListValue

func ListValue(lst *[]string, defaultList []string) flag.Value

func MigrateBlocks

func MigrateBlocks(ctx context.Context, from blockstore.Blockstore, to blockstore.Blockstore) error

MigrateBlocks transfers all blocks from a blockstore to another

func MigrateSelectBlocks

func MigrateSelectBlocks(from blockstore.Blockstore, to blockstore.Blockstore, root cid.Cid, sel ipld.Node) error

MigrateSelectBlocks transfers blocks from a blockstore to another for a given block selection

func RepoExists

func RepoExists(path string) (bool, error)

RepoExists checks if we have a datastore directory already created

func RepoPath

func RepoPath() (string, error)

RepoPath is akin to IPFS: ~/.pop by default or changed via $POP_PATH

func StringsToPeerIDs

func StringsToPeerIDs(strIDs []string) ([]peer.ID, error)

StringsToPeerIDs parses a list of strings into peer IDs

func WalkDAG

func WalkDAG(
	root cid.Cid,
	bs blockstore.Blockstore,
	sel ipld.Node,
	f func(blocks.Block) error,
	missingF func(cid.Cid, error) error) error

WalkDAG executes a DAG traversal for a given root and selector and calls a callback function for every block loaded during the traversal an optional callback also returns missing block and forwards the errors

Types

type DAGStat

type DAGStat struct {
	Size      int
	NumBlocks int
}

DAGStat describes a DAG

func Stat

func Stat(store *multistore.Store, root cid.Cid, sel ipld.Node) (DAGStat, error)

Stat returns stats about a selected part of DAG given a cid The cid must be registered in the index

type FileType

type FileType int
const (
	FTUnknown FileType = iota
	FTApplication
	FTAudio
	FTVideo
	FTImage
	FTChemical
	FTFont
	FTMessage
	FTModel
	FTText
	FTArchive
)

func DetectFileType

func DetectFileType(path string, buf io.ReadSeeker) FileType

DetectFileType detects the FileType of a file using it's extension. The path argument should be absolute

type KeyList

type KeyList []string

KeyList is a list of strings representing all the keys in an IPLD Map

func MapLoadableKeys

func MapLoadableKeys(root cid.Cid, lsys ipld.LinkSystem) (KeyList, error)

MapLoadableKeys returns all the keys of a Tx, given its cid and a loader this only returns the keys for entries where the blocks are available in the blockstore it supports both dagpb and dagcbor nodes

func MapMissingKeys

func MapMissingKeys(root cid.Cid, lsys ipld.LinkSystem) (KeyList, error)

MapMissingKeys returns keys for values for which the links are not loadable

func (KeyList) AsBytes

func (kl KeyList) AsBytes() [][]byte

AsBytes returns all the keys as byte slices

func (KeyList) Sorted

func (kl KeyList) Sorted() KeyList

Sorted ensures the key list is sorted

Jump to

Keyboard shortcuts

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