ipfs

package module
v0.0.0-...-e53c9cb Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: GPL-3.0 Imports: 56 Imported by: 0

README

Why go-ipfs-lite?

go-ipfs-lite is a minimum IPFS node implementation in Go. The official IPFS implementation Kubo offers maximum customization capability by allowing developers to inject their own implementation of its building components. However, the extensibility comes with complexity, which becomes a hurdle for developers who want quick integration. go-ipfs-lite strips out most of the interfaces and only accept plugins for basic components such as 'Datastore' and 'Blockstore'. The slim node becomes very easy to integrate and light-weight to operate.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// BlockSizeLimit specifies the maximum size an imported block can have.
	BlockSizeLimit = 1048576 // 1 MB

)
View Source
var (
	ErrDataSourceTypeNotSupported = errors.New("data source type not supported")
)
View Source
var (
	ErrEmptyData = errors.New("empty data to build DAG")
)
View Source
var (
	// ErrSizeLimitExceeded signals that a block is larger than BlockSizeLimit.
	ErrSizeLimitExceeded = errors.New("object size limit exceeded")
)

Functions

func ExternFetchCid

func ExternFetchCid(cid cid.Cid) ([]byte, error)

ExternFetchCid fetches IPFS block data for the given CID from an external source. If the fetch is successful, that means data becomes visible by IPFS peers.

func GenCid

func GenCid(
	ctx context.Context,
	src any,
	opts CidOpts,
) (cid.Cid, error)

GenCid calculates CID for the given data source.

func NewDagNode

func NewDagNode(t pb.Data_DataType, cb cid.Builder, tag any) *dagNode

NewDagNode creates a new empty dagNode.

func NewDataProvider

func NewDataProvider(r io.Reader, splitSize int64) dataProvider

NewDataProvider creates a default dataProvider that splits data from the provided io.Reader in splitSize.

Types

type Chunk

type Chunk struct {
	Data []byte
	Tag  any
}

Chunk defines a chunk returned by dataProvider. The chunk is passed back to blockstore after DAG building. The tag can be any data which is treated by the DAG builder. User can use tag to track chunk data.

func NewChunk

func NewChunk(d []byte, tag any) *Chunk

func (*Chunk) Size

func (p *Chunk) Size() int

type CidOpts

type CidOpts struct {
	// DataType sets which dag type to generate for the object.
	DagType DagType
	// ChunkSize sets the split size for each leave node, 0 for using default size.
	ChunkSize int64
	// Number of linkes per block in DAG.
	LinksPerBlock int
	// RawLeaves sets if leaf nodes are generated as RawNode.
	RawLeaves bool
	// CidBuilder v0 or v1. Default to v1.
	CidBuilder cid.Builder
}

CidOpts contains configurable parameters for generating CID.

type Config

type Config struct {
	OfflineMode           bool
	SecretKey             crypto.PrivKey
	ListenAddrs           []multiaddr.Multiaddr
	Bootstrappers         []peer.AddrInfo
	MinConnections        int
	MaxConnections        int
	ConnectionGracePeriod time.Duration
	Datastore             datastore.Batching
	Blockstore            blockstore.Blockstore
	ReprovideInterval     time.Duration
	CidBuilder            cid.Builder
	ConnectionLogging     bool
}

type DagType

type DagType int
const (
	DagBalanced DagType = 0
	DagTrickle          = 1
)

type ExtendedNode

type ExtendedNode struct {
	ipld.Node
	// contains filtered or unexported fields
}

ExtendedNode extends ipld.Node interface with extra file size and origin chunk data.

func NewExtendedNode

func NewExtendedNode(
	nd ipld.Node,
	size uint64,
	c *Chunk,
	tag any,
) *ExtendedNode

func (*ExtendedNode) Base

func (n *ExtendedNode) Base() ipld.Node

Base returns the base ipld.Node type.

func (*ExtendedNode) Chunk

func (n *ExtendedNode) Chunk() *Chunk

Chunk returns the original chunk supplied by dataProvider. Nil for non-leaf node.

func (*ExtendedNode) FileSize

func (n *ExtendedNode) FileSize() uint64

FileSize returns the file (or portion of it) size represented by the current node.

func (*ExtendedNode) PutOptsTag

func (n *ExtendedNode) PutOptsTag() any

PutOptsTag returns the passed through tag from PutOpts.

func (*ExtendedNode) Root

func (n *ExtendedNode) Root() bool

Root returns if the node is a DAG root.

func (*ExtendedNode) SetRoot

func (n *ExtendedNode) SetRoot()

SetRoot marks the node as DAG root.

type Node

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

Node is a customized IPFS lite-node. The code was originally forked github.com/hsanjuan/ipfs-lite with substantial refactoring with relay support.

func New

func New(ctx context.Context, cfg Config) (*Node, error)

New creates a new Node instance. An empty Config which fallbacks to default settings should work.

func (*Node) BlockService

func (n *Node) BlockService() blockservice.BlockService

BlockService returns the underlying blockservice implementation.

func (*Node) BlockStore

func (n *Node) BlockStore() blockstore.Blockstore

BlockStore returns the blockstore.

func (*Node) Exchange

func (n *Node) Exchange() exchange.Interface

Exchange returns the bitswap.

func (*Node) GetObject

func (n *Node) GetObject(ctx context.Context, c cid.Cid) (ReadSeekCloser, error)

GetObject returns a reader to a data blob as identified by the given root CID. The object must have been added as a UnixFS DAG (default for IPFS).

func (*Node) HasBlock

func (n *Node) HasBlock(ctx context.Context, c cid.Cid) (bool, error)

HasBlock returns whether a given block is available locally.

func (*Node) NumPeers

func (n *Node) NumPeers() int

NumPeers returns the number of peers the IPFS host is connected to.

func (*Node) PutObject

func (n *Node) PutObject(
	ctx context.Context,
	src any,
	opts PutOpts,
) (ipld.Node, error)

PutObject chunks data supplied by io.Reader and builds a DAG for splitted data nodes. The root ipld.Node is returned.

func (*Node) Session

func (n *Node) Session(ctx context.Context) ipld.NodeGetter

Session returns a session-based NodeGetter.

type NoopDAGService

type NoopDAGService struct {
}

func (NoopDAGService) Add

Add implements the DAGService interface.

func (NoopDAGService) AddMany

func (_ NoopDAGService) AddMany(context.Context, []ipld.Node) error

AddMany implements the DAGService interface.

func (NoopDAGService) Get

func (_ NoopDAGService) Get(context.Context, cid.Cid) (ipld.Node, error)

Get implements the DAGService interface.

func (NoopDAGService) GetMany

func (_ NoopDAGService) GetMany(
	context.Context,
	[]cid.Cid,
) <-chan *ipld.NodeOption

GetMany implements the DAGService interface.

func (NoopDAGService) Remove

func (_ NoopDAGService) Remove(context.Context, cid.Cid) error

Remove implements the DAGService interface.

func (NoopDAGService) RemoveMany

func (_ NoopDAGService) RemoveMany(context.Context, []cid.Cid) error

RemoveMany implements the DAGService interface.

type PutOpts

type PutOpts struct {
	// DataType sets which dag type to generate for the object.
	DagType DagType
	// ChunkSize sets the split size for generating DAG leave nodes.
	ChunkSize int64
	// Number of linkes per block in DAG.
	LinksPerBlock int
	// RawLeaves sets if leaf nodes are generated as RawNode.
	RawLeaves bool
	// Tag is custom data to be passed through all the way to blockstore.
	Tag any
}

PutOpts contains configurable parameters for file DAG building.

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

A ReadSeekCloser implements interfaces to read, seek and close.

type VerifBS

type VerifBS struct {
	blockstore.Blockstore
}

Copied from github.com/ipfs/kubo/thirdparty/verifbs to avoid dependency on Kubo, which introduces version conflicts for libp2p-core

func (*VerifBS) Get

func (bs *VerifBS) Get(ctx context.Context, c cid.Cid) (blocks.Block, error)

func (*VerifBS) Put

func (bs *VerifBS) Put(ctx context.Context, b blocks.Block) error

func (*VerifBS) PutMany

func (bs *VerifBS) PutMany(ctx context.Context, blks []blocks.Block) error

Jump to

Keyboard shortcuts

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