ipfslite

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 43 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.

Running Example

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

ngi logo eu logo

Documentation

Overview

Package ipfslite is a lightweight IPFS peer which runs the minimal setup to provide an `ipld.DAGService`, "Add" and "Get" UnixFS files from IPFS.

Index

Constants

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

Variables

View Source
var DefaultBootstrapAddresses = []string{
	"/ip4/52.66.216.67/tcp/4501/p2p/QmevJNn8Um8HQV5VYYapQmgqFDYQMxXL1HLTAReHBXosXh",
}

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 a 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)

func WithCrdtNamespace

func WithCrdtNamespace(ns string) Option

func WithCrdtTopic

func WithCrdtTopic(topic string) Option

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
}

type Peer

type Peer struct {
	Ctx             context.Context
	Cancel          context.CancelFunc
	Host            host.Host
	Store           datastore.Batching
	DHT             routing.Routing
	Repo            repo.Repo
	Provider        provider.System
	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) Disconnect

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

Disconnect host from a given peer

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) 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

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.

Directories

Path Synopsis
examples
litepeer command
mobilepeer 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.

Jump to

Keyboard shortcuts

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