ipfs

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: AGPL-3.0 Imports: 52 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MaxFileSizeBytes is the maximum size of a file to be published to IPFS
	MaxFileSizeBytes = 1024 * 1024 * 100 // 100 MB
	// RetrievedFileCacheSize is the maximum number of files to be cached in memory
	RetrievedFileCacheSize = 128
)
View Source
const ChunkerTypeSize = "size-262144"

ChunkerTypeSize is the chunker type used by IPFS to calculate to build the DAG.

Variables

View Source
var ConfigRoot string

Functions

func CIDequals

func CIDequals(cid1, cid2 string) bool

CIDequals compares two Cids (v0 or v1) and returns true if they are equal. It compares the hash of the Cid, not the Cid itself (which contains also the codec and encoding). It strips the ipfs:// prefix and the /ipfs/ prefix if present.

func CalculateCIDv1json

func CalculateCIDv1json(data []byte) string

CalculateCIDv1json calculates the IPFS Cid hash (v1) from a bytes buffer, using parameters Codec: DagJSON, MhType: SHA2_256

func NewIPFSkey

func NewIPFSkey() []byte

NewIPFSkey generates a new IPFS private key (ECDSA/256bit) and returns its marshaled bytes representation.

Types

type Handler

type Handler struct {
	Node     *ipfscore.IpfsNode
	CoreAPI  coreiface.CoreAPI
	DataDir  string
	LogLevel string
	// contains filtered or unexported fields
}

Handler is the IPFS data storage node handler.

func MockIPFS

func MockIPFS(t testing.TB) *Handler

MockIPFS returns a Handler with a (offline, nilrepo) IPFS node with a functional CoreAPI

func (*Handler) AddKeyToKeystore

func (i *Handler) AddKeyToKeystore(keyalias string, privkey []byte) error

AddKeyToKeystore adds a marshaled IPFS private key to the IPFS keystore. The key is identified by a unique alias name which can be used for referncing that key when using some other IPFS methods. Compatible Keys can be generated with NewIPFSkey() function.

func (*Handler) Init

func (i *Handler) Init(d *types.DataStore) error

Init initializes the IPFS node handler and repository.

func (*Handler) ListPins

func (i *Handler) ListPins(ctx context.Context) (map[string]string, error)

ListPins returns a map of all pinned CIDs and their types

func (*Handler) Pin

func (i *Handler) Pin(ctx context.Context, path string) error

Pin adds a file to ipfs and returns the resulting CID v1.

func (*Handler) Publish

func (i *Handler) Publish(ctx context.Context, msg []byte) (cid string, err error)

Publish publishes a file or message to ipfs and returns the resulting CID v1.

func (*Handler) PublishIPNSpath

func (i *Handler) PublishIPNSpath(ctx context.Context, path string, keyalias string) (ipns.Name, ipfspath.ImmutablePath, error)

PublishIPNSpath creates or updates an IPNS record with the content of a filesystem path (a single file or a directory).

The IPNS record is published under the scope of the private key identified by the keyalias parameter. New keys can be created using method AddKeyToKeystore and function NewIPFSkey() both available on this package.

The execution of this method might take a while (some minutes), so the caller must handle properly the logic by using goroutines, channels or other mechanisms in order to not block the whole program execution.

func (*Handler) PublishReader added in v1.10.0

func (i *Handler) PublishReader(ctx context.Context, buf io.Reader) (cid string, err error)

PublishReader publishes a reader buffer to ipfs and returns the resulting CID v1.

func (*Handler) Retrieve

func (i *Handler) Retrieve(ctx context.Context, path string, maxSize int64) ([]byte, error)

Retrieve gets an IPFS file (either from the p2p network or from the local cache). If maxSize is 0, it is set to the hardcoded maximum of MaxFileSizeBytes.

func (*Handler) RetrieveDir added in v1.10.0

func (i *Handler) RetrieveDir(ctx context.Context, path string, maxSize int64) (map[string][]byte, error)

RetrieveDir gets an IPFS directory and returns a map of all files and their content. It only supports 1 level of directory depth, so subdirectories are ignored.

func (*Handler) SetMultiAddress

func (i *Handler) SetMultiAddress(addr string) (err error)

SetMultiAddress sets the multiaddress of the IPFS node.

func (*Handler) Stats

func (i *Handler) Stats() map[string]any

Stats returns stats about the IPFS node.

func (*Handler) Stop

func (i *Handler) Stop() error

Stop stops the IPFS node handler.

func (*Handler) URIprefix

func (*Handler) URIprefix() string

URIprefix returns the URI prefix which identifies the protocol

func (*Handler) Unpin

func (i *Handler) Unpin(ctx context.Context, path string) error

Unpin removes a file pin from ipfs.

Directories

Path Synopsis
Package ipfsconnect provides a service to maintain persistent connections (PersistPeers) between two or more IPFS nodes
Package ipfsconnect provides a service to maintain persistent connections (PersistPeers) between two or more IPFS nodes

Jump to

Keyboard shortcuts

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