ipfslite

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

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

Go to latest
Published: Nov 11, 2021 License: Apache-2.0 Imports: 44 Imported by: 0

README

IPFS-Lite

Go Reference Go Report Card Actions Status codecov

IPFS-Lite is an embeddable, lightweight IPFS peer. This fork started from ipfs-lite.

It offers all the features of main ipfs-lite. For certain requirements of datahop it adds some more features of full ipfs, such as config, repo, leveldb etc.

Examples

cli client
 go run ./examples/litepeer/litepeer.go
mobile client
  go run ./examples/mobilepeer/mobilepeer.go

Objectives

  • create cache repo as ipfs
  • have persistent config information (Id, keys, ports, bootstraps etc)
  • use leveldb as datastore to set up peer
  • generate gomobile binding for android
  • adding content
  • replicating content
  • remove content
  • remove respective replication info for removed content
  • bootstrap mobile client
  • cli for bootstrap peer

Documentation

Go pkg docs

License

Copyright 2021 Datahop

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Acknowledgment

This software is part of the NGI Pointer project "Incentivised Content Dissemination at the Network Edge" that has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 871528

go run main.go server --config ~/.magic.yml

Documentation

Index

Constants

View Source
const (
	// ServiceTag is used for mDNS
	ServiceTag = "_datahop-discovery._tcp"
)

Variables

This section is empty.

Functions

func DefaultBootstrapPeers

func DefaultBootstrapPeers() []peer.AddrInfo

DefaultBootstrapPeers returns the default datahop bootstrap peers (for use with NewLibp2pHost.

func SetupLibp2p

func SetupLibp2p(
	ctx context.Context,
	hostKey crypto.PrivKey,
	listenAddrs []multiaddr.Multiaddr,
	ds datastore.Batching,
	opts ...libp2p.Option,
) (host.Host, *dualdht.DHT, error)

SetupLibp2p returns a routed host and DHT instances that can be used to easily create an ipfslite Peer. You may consider to use Peer.Bootstrap() or Peer.Connect() after creating the IPFS-Lite Peer to connect to other peers.

Additional libp2p options can be passed. Interesting options to pass: NATPortMap() EnableAutoRelay(), libp2p.EnableNATService(), DisableRelay(), ConnectionManager(...)... see https://godoc.org/github.com/libp2p/go-libp2p#Option for more info.

Types

type AddParams

type AddParams struct {
	Layout    string
	Chunker   string
	RawLeaves bool
	Hidden    bool
	Shard     bool
	NoCopy    bool
	HashFun   string
}

AddParams contains all of the configurable parameters needed to specify the importing process of a file.

type Option

type Option func(*Options)

Option is interface for setting up the datahop ipfslite node

func WithCrdtNamespace

func WithCrdtNamespace(ns string) Option

WithCrdtNamespace sets the replication crdt namespace

func WithCrdtTopic

func WithCrdtTopic(topic string) Option

WithCrdtTopic sets the replication crdt listen topic

func WithRebroadcastInterval

func WithRebroadcastInterval(interval time.Duration) Option

WithRebroadcastInterval changes default crdt rebroadcast interval

func WithmDNS

func WithmDNS(withmDNS bool) Option

WithmDNS decides if the ipfs node will start with mDNS or not

func WithmDNSInterval

func WithmDNSInterval(interval time.Duration) Option

WithmDNSInterval changes default mDNS rebroadcast interval

type Options

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

Options for setting up the datahop ipfslite node

type Peer

type Peer struct {
	Ctx             context.Context
	Cancel          context.CancelFunc
	Host            host.Host
	Store           datastore.Batching
	DHT             routing.Routing
	Repo            repo.Repo
	ipld.DAGService // become a DAG service

	Manager   *replication.Manager
	Stopped   chan bool
	CrdtTopic string
	// contains filtered or unexported fields
}

Peer is an IPFS-Lite peer. It provides a DAG service that can fetch and put blocks from/to the IPFS network.

func New

func New(
	ctx context.Context,
	cancelFunc context.CancelFunc,
	r repo.Repo,
	opts ...Option,
) (*Peer, error)

New creates an IPFS-Lite Peer. It uses the given datastore, libp2p Host and Routing (usuall the DHT). Peer implements the ipld.DAGService interface.

func (*Peer) AddFile

func (p *Peer) AddFile(ctx context.Context, r io.Reader, params *AddParams) (ipld.Node, error)

AddFile chunks and adds content to the DAGService from a reader. The content is stored as a UnixFS DAG (default for IPFS). It returns the root ipld.Node.

func (*Peer) BlockStore

func (p *Peer) BlockStore() blockstore.Blockstore

BlockStore offers access to the blockstore underlying the Peer's DAGService.

func (*Peer) Bootstrap

func (p *Peer) Bootstrap(peers []peer.AddrInfo)

Bootstrap is an optional helper to connect to the given peers and bootstrap the Peer DHT (and Bitswap). This is a best-effort function. Errors are only logged and a warning is printed when less than half of the given peers could be contacted. It is fine to pass a list where some peers will not be reachable.

func (*Peer) Connect

func (p *Peer) Connect(ctx context.Context, pi peer.AddrInfo) error

Connect connects host to a given peer

func (*Peer) DeleteFile

func (p *Peer) DeleteFile(ctx context.Context, c cid.Cid) error

DeleteFile removes content from blockstore by its root CID. The file must have been added as a UnixFS DAG (default for IPFS).

func (*Peer) Disconnect

func (p *Peer) Disconnect(pi peer.AddrInfo) error

Disconnect host from a given peer

func (*Peer) Download

func (p *Peer) Download(ctx context.Context, c cid.Cid) error

Download will get the content by its root CID. Read it till the end.

func (*Peer) FindProviders

func (p *Peer) FindProviders(ctx context.Context, id cid.Cid) []peer.ID

FindProviders check dht to check for providers of a given cid

func (*Peer) GetFile

func (p *Peer) GetFile(ctx context.Context, c cid.Cid) (ufsio.ReadSeekCloser, error)

GetFile returns a reader to a file as identified by its root CID. The file must have been added as a UnixFS DAG (default for IPFS).

func (*Peer) HandlePeerFound

func (p *Peer) HandlePeerFound(pi peer.AddrInfo)

HandlePeerFound tries to connect to a given peerinfo

func (*Peer) HandlePeerFoundWithError

func (p *Peer) HandlePeerFoundWithError(pi peer.AddrInfo) error

HandlePeerFoundWithError tries to connect to a given peerinfo, returns error if failed

func (*Peer) HasBlock

func (p *Peer) HasBlock(c cid.Cid) (bool, error)

HasBlock returns whether a given block is available locally. It is a shorthand for .Blockstore().Has().

func (*Peer) IsOnline

func (p *Peer) IsOnline() bool

IsOnline returns if the node ios online

func (*Peer) Peers

func (p *Peer) Peers() []string

Peers returns a list of connected peers

func (*Peer) Session

func (p *Peer) Session(ctx context.Context) ipld.NodeGetter

Session returns a session-based NodeGetter.

func (*Peer) ZeroConfScan

func (p *Peer) ZeroConfScan()

Directories

Path Synopsis
cli
cmd
out
cmd
magic command
examples
litepeer command
mobilepeer command
node command
internal
Package datahop is a mobile client for running a minimalistic datahop ipfslite node.
Package datahop is a mobile client for running a minimalistic datahop ipfslite node.
pkg
build
Package build contains build-related variables set at compile time.
Package build contains build-related variables set at compile time.
cli
log
util/hyperloglog
Package hyperloglog wraps github.com/clarkduvall/hyperloglog with mutexes
Package hyperloglog wraps github.com/clarkduvall/hyperloglog with mutexes
third

Jump to

Keyboard shortcuts

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