core

package
v0.0.0-...-8dabba5 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: MIT Imports: 83 Imported by: 0

Documentation

Overview

Package core implements the IpfsNode object and related methods.

Packages underneath core/ provide a (relatively) stable, low-level API to carry out most IPFS-related tasks. For more details on the other interfaces and how core/... fits into the bigger IPFS picture, see:

$ godoc github.com/ipfs/go-ipfs

Index

Constants

View Source
const IpnsValidatorTag = "ipns"

Variables

View Source
var DefaultBootstrapConfig = BootstrapConfig{
	MinPeerThreshold:  4,
	Period:            30 * time.Second,
	ConnectionTimeout: (30 * time.Second) / 3,
}

DefaultBootstrapConfig specifies default sane parameters for bootstrapping.

View Source
var ErrNoNamesys = errors.New(
	"core/resolve: no Namesys on IpfsNode - can't resolve ipns entry")

ErrNoNamesys is an explicit error for when an IPFS node doesn't (yet) have a name system

View Source
var ErrNotEnoughBootstrapPeers = errors.New("not enough bootstrap peers to bootstrap")

ErrNotEnoughBootstrapPeers signals that we do not have enough bootstrap peers to bootstrap correctly.

Functions

func Bootstrap

func Bootstrap(n *IpfsNode, cfg BootstrapConfig) (io.Closer, error)

Bootstrap kicks off IpfsNode bootstrapping. This function will periodically check the number of open connections and -- if there are too few -- initiate connections to well-known bootstrap peers. It also kicks off subsystem bootstrapping (i.e. routing).

func Resolve

func Resolve(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (ipld.Node, error)

Resolve resolves the given path by parsing out protocol-specific entries (e.g. /ipns/<node-key>) and then going through the /ipfs/ entries and returning the final node.

func ResolveIPNS

func ResolveIPNS(ctx context.Context, nsys namesys.NameSystem, p path.Path) (path.Path, error)

ResolveIPNS resolves /ipns paths

func ResolveToCid

func ResolveToCid(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (*cid.Cid, error)

ResolveToCid resolves a path to a cid.

It first checks if the path is already in the form of just a cid (<cid> or /ipfs/<cid>) and returns immediately if so. Otherwise, it falls back onto Resolve to perform resolution of the dagnode being referenced.

Types

type BootstrapConfig

type BootstrapConfig struct {

	// MinPeerThreshold governs whether to bootstrap more connections. If the
	// node has less open connections than this number, it will open connections
	// to the bootstrap nodes. From there, the routing system should be able
	// to use the connections to the bootstrap nodes to connect to even more
	// peers. Routing systems like the IpfsDHT do so in their own Bootstrap
	// process, which issues random queries to find more peers.
	MinPeerThreshold int

	// Period governs the periodic interval at which the node will
	// attempt to bootstrap. The bootstrap process is not very expensive, so
	// this threshold can afford to be small (<=30s).
	Period time.Duration

	// ConnectionTimeout determines how long to wait for a bootstrap
	// connection attempt before cancelling it.
	ConnectionTimeout time.Duration

	// BootstrapPeers is a function that returns a set of bootstrap peers
	// for the bootstrap process to use. This makes it possible for clients
	// to control the peers the process uses at any moment.
	BootstrapPeers func() []pstore.PeerInfo
}

BootstrapConfig specifies parameters used in an IpfsNode's network bootstrapping process.

func BootstrapConfigWithPeers

func BootstrapConfigWithPeers(pis []pstore.PeerInfo) BootstrapConfig

type BuildCfg

type BuildCfg struct {
	// If online is set, the node will have networking enabled
	Online bool

	// ExtraOpts is a map of extra options used to configure the ipfs nodes creation
	ExtraOpts map[string]bool

	// If permanent then node should run more expensive processes
	// that will improve performance in long run
	Permanent bool

	// DisableEncryptedConnections disables connection encryption *entirely*.
	// DO NOT SET THIS UNLESS YOU'RE TESTING.
	DisableEncryptedConnections bool

	// If NilRepo is set, a repo backed by a nil datastore will be constructed
	NilRepo bool

	Routing RoutingOption
	Host    HostOption
	Repo    repo.Repo
}

type ConstructPeerHostOpts

type ConstructPeerHostOpts struct {
	AddrsFactory      p2pbhost.AddrsFactory
	DisableNatPortMap bool
	DisableRelay      bool
	EnableRelayHop    bool
	ConnectionManager ifconnmgr.ConnManager
}

type DiscoveryOption

type DiscoveryOption func(context.Context, p2phost.Host) (discovery.Service, error)

type HostOption

type HostOption func(ctx context.Context, id peer.ID, ps pstore.Peerstore, options ...libp2p.Option) (p2phost.Host, error)
var DefaultHostOption HostOption = constructPeerHost

type IpfsNode

type IpfsNode struct {

	// Self
	Identity peer.ID // the local node's identity

	Repo repo.Repo

	// Local node
	Pinning         pin.Pinner // the pinning manager
	Mounts          Mounts     // current mount state, if any.
	PrivateKey      ic.PrivKey // the local node's private Key
	PNetFingerprint []byte     // fingerprint of private network

	// Services
	Peerstore       pstore.Peerstore     // storage for other Peer instances
	Blockstore      bstore.GCBlockstore  // the block store (lower level)
	Filestore       *filestore.Filestore // the filestore blockstore
	BaseBlocks      bstore.Blockstore    // the raw blockstore, no filestore wrapping
	GCLocker        bstore.GCLocker      // the locker used to protect the blockstore during gc
	Blocks          bserv.BlockService   // the block service, get/add blocks.
	DAG             ipld.DAGService      // the merkle dag service, get/add objects.
	Resolver        *resolver.Resolver   // the path resolution system
	Reporter        metrics.Reporter
	Discovery       discovery.Service
	FilesRoot       *mfs.Root
	RecordValidator record.Validator

	// Online
	PeerHost     p2phost.Host        // the network host (server+client)
	Bootstrapper io.Closer           // the periodic bootstrapper
	Routing      routing.IpfsRouting // the routing system. recommend ipfs-dht
	Exchange     exchange.Interface  // the block exchange + strategy (bitswap)
	Namesys      namesys.NameSystem  // the name system, resolves paths to hashes
	Ping         *ping.PingService
	Reprovider   *rp.Reprovider // the value reprovider system
	IpnsRepub    *ipnsrp.Republisher

	Floodsub *floodsub.PubSub
	PSRouter *psrouter.PubsubValueStore
	DHT      *dht.IpfsDHT
	P2P      *p2p.P2P
	// contains filtered or unexported fields
}

IpfsNode is IPFS Core module. It represents an IPFS instance.

func NewNode

func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error)

NewNode constructs and returns an IpfsNode using the given cfg.

func (*IpfsNode) Bootstrap

func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error

Bootstrap will set and call the IpfsNodes bootstrap function.

func (*IpfsNode) Close

func (n *IpfsNode) Close() error

Close calls Close() on the Process object

func (*IpfsNode) Context

func (n *IpfsNode) Context() context.Context

Context returns the IpfsNode context

func (*IpfsNode) GetKey

func (n *IpfsNode) GetKey(name string) (ic.PrivKey, error)

GetKey will return a key from the Keystore with name `name`.

func (*IpfsNode) HandlePeerFound

func (n *IpfsNode) HandlePeerFound(p pstore.PeerInfo)

HandlePeerFound attempts to connect to peer from `PeerInfo`, if it fails logs a warning log.

func (*IpfsNode) LoadPrivateKey

func (n *IpfsNode) LoadPrivateKey() error

func (*IpfsNode) LocalMode

func (n *IpfsNode) LocalMode() bool

LocalMode returns whether or not the IpfsNode is in LocalMode

func (*IpfsNode) OnlineMode

func (n *IpfsNode) OnlineMode() bool

OnlineMode returns whether or not the IpfsNode is in OnlineMode.

func (*IpfsNode) Process

func (n *IpfsNode) Process() goprocess.Process

Process returns the Process object

func (*IpfsNode) SetLocal

func (n *IpfsNode) SetLocal(isLocal bool)

SetLocal will set the IpfsNode to local mode

func (*IpfsNode) SetupOfflineRouting

func (n *IpfsNode) SetupOfflineRouting() error

SetupOfflineRouting instantiates a routing system in offline mode. This is primarily used for offline ipns modifications.

type Mounts

type Mounts struct {
	Ipfs mount.Mount
	Ipns mount.Mount
}

Mounts defines what the node's mount state is. This should perhaps be moved to the daemon or mount. It's here because it needs to be accessible across daemon requests.

type RoutingOption

var DHTClientOption RoutingOption = constructClientDHTRouting
var DHTOption RoutingOption = constructDHTRouting

Directories

Path Synopsis
Package commands implements the ipfs command interface Using github.com/ipfs/go-ipfs/commands to define the command line and HTTP APIs.
Package commands implements the ipfs command interface Using github.com/ipfs/go-ipfs/commands to define the command line and HTTP APIs.
dag
e
Package coreapi provides direct access to the core commands in IPFS.
Package coreapi provides direct access to the core commands in IPFS.
interface
Package iface defines IPFS Core API which is a set of interfaces used to interact with IPFS nodes.
Package iface defines IPFS Core API which is a set of interfaces used to interact with IPFS nodes.
Package corehttp provides utilities for the webui, gateways, and other high-level HTTP interfaces to IPFS.
Package corehttp provides utilities for the webui, gateways, and other high-level HTTP interfaces to IPFS.
Package corerepo provides pinning and garbage collection for local IPFS block services.
Package corerepo provides pinning and garbage collection for local IPFS block services.

Jump to

Keyboard shortcuts

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