/* Package core implements the Dms3Node object and related methods. Packages underneath core/ provide a (relatively) stable, low-level API to carry out most DMS3-related tasks. For more details on the other interfaces and how core/... fits into the bigger DMS3 picture, see: $ godoc gitlab.dms3.io/dms3/go-dms3 */ package core import ( "context" "io" "gitlab.dms3.io/dms3/go-filestore" goprocess "github.com/jbenet/goprocess" bserv "gitlab.dms3.io/dms3/go-blockservice" bstore "gitlab.dms3.io/dms3/go-dms3-blockstore" exchange "gitlab.dms3.io/dms3/go-dms3-exchange-interface" pin "gitlab.dms3.io/dms3/go-dms3-pinner" provider "gitlab.dms3.io/dms3/go-dms3-provider" "gitlab.dms3.io/dms3/go-graphsync" ld "gitlab.dms3.io/dms3/go-ld-format" logging "gitlab.dms3.io/dms3/go-log" mfs "gitlab.dms3.io/dms3/go-mfs" resolver "gitlab.dms3.io/dms3/go-path/resolver" ma "gitlab.dms3.io/mf/go-multiaddr" connmgr "gitlab.dms3.io/p2p/go-p2p-core/connmgr" ic "gitlab.dms3.io/p2p/go-p2p-core/crypto" p2phost "gitlab.dms3.io/p2p/go-p2p-core/host" metrics "gitlab.dms3.io/p2p/go-p2p-core/metrics" peer "gitlab.dms3.io/p2p/go-p2p-core/peer" pstore "gitlab.dms3.io/p2p/go-p2p-core/peerstore" routing "gitlab.dms3.io/p2p/go-p2p-core/routing" ddht "gitlab.dms3.io/p2p/go-p2p-kad-dht/dual" pubsub "gitlab.dms3.io/p2p/go-p2p-pubsub" psrouter "gitlab.dms3.io/p2p/go-p2p-pubsub-router" record "gitlab.dms3.io/p2p/go-p2p-record" "gitlab.dms3.io/p2p/go-p2p/p2p/discovery" p2pbhost "gitlab.dms3.io/p2p/go-p2p/p2p/host/basic" "gitlab.dms3.io/dms3/go-dms3/core/bootstrap" "gitlab.dms3.io/dms3/go-dms3/core/node" "gitlab.dms3.io/dms3/go-dms3/core/node/dms3p2p" "gitlab.dms3.io/dms3/go-dms3/fuse/mount" "gitlab.dms3.io/dms3/go-dms3/namesys" dms3nsrp "gitlab.dms3.io/dms3/go-dms3/namesys/republisher" "gitlab.dms3.io/dms3/go-dms3/p2p" "gitlab.dms3.io/dms3/go-dms3/peering" "gitlab.dms3.io/dms3/go-dms3/repo" ) var log = logging.Logger("core") // Dms3Node is DMS3 Core module. It represents an DMS3 instance. type Dms3Node struct { // Self Identity peer.ID // the local node's identity Repo repo.Repo // Local node Pinning pin.Pinner // the pinning manager Mounts Mounts `optional:"true"` // current mount state, if any. PrivateKey ic.PrivKey `optional:"true"` // the local node's private Key PNetFingerprint dms3p2p.PNetFingerprint `optional:"true"` // fingerprint of private network // Services Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances Blockstore bstore.GCBlockstore // the block store (lower level) Filestore *filestore.Filestore `optional:"true"` // the filestore blockstore BaseBlocks node.BaseBlocks // 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 ld.DAGService // the merkle dag service, get/add objects. Resolver *resolver.Resolver // the path resolution system Reporter *metrics.BandwidthCounter `optional:"true"` Discovery discovery.Service `optional:"true"` FilesRoot *mfs.Root RecordValidator record.Validator // Online PeerHost p2phost.Host `optional:"true"` // the network host (server+client) Peering peering.PeeringService `optional:"true"` Filters *ma.Filters `optional:"true"` Bootstrapper io.Closer `optional:"true"` // the periodic bootstrapper Routing routing.Routing `optional:"true"` // the routing system. recommend dms3-dht Exchange exchange.Interface // the block exchange + strategy (bitswap) Namesys namesys.NameSystem // the name system, resolves paths to hashes Provider provider.System // the value provider system Dms3NsRepub *dms3nsrp.Republisher `optional:"true"` GraphExchange graphsync.GraphExchange `optional:"true"` PubSub *pubsub.PubSub `optional:"true"` PSRouter *psrouter.PubsubValueStore `optional:"true"` DHT *ddht.DHT `optional:"true"` P2P *p2p.P2P `optional:"true"` Process goprocess.Process ctx context.Context stop func() error // Flags IsOnline bool `optional:"true"` // Online is set when networking is enabled. IsDaemon bool `optional:"true"` // Daemon is set when running on a long-running daemon. } // 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 Mounts struct { Dms3 mount.Mount Dms3Ns mount.Mount } // Close calls Close() on the App object func (n *Dms3Node) Close() error { return n.stop() } // Context returns the Dms3Node context func (n *Dms3Node) Context() context.Context { if n.ctx == nil { n.ctx = context.TODO() } return n.ctx } // Bootstrap will set and call the Dms3Nodes bootstrap function. func (n *Dms3Node) Bootstrap(cfg bootstrap.BootstrapConfig) error { // TODO what should return value be when in offlineMode? if n.Routing == nil { return nil } if n.Bootstrapper != nil { n.Bootstrapper.Close() // stop previous bootstrap process. } // if the caller did not specify a bootstrap peer function, get the // freshest bootstrap peers from config. this responds to live changes. if cfg.BootstrapPeers == nil { cfg.BootstrapPeers = func() []peer.AddrInfo { ps, err := n.loadBootstrapPeers() if err != nil { log.Warn("failed to parse bootstrap peers from config") return nil } return ps } } var err error n.Bootstrapper, err = bootstrap.Bootstrap(n.Identity, n.PeerHost, n.Routing, cfg) return err } func (n *Dms3Node) loadBootstrapPeers() ([]peer.AddrInfo, error) { cfg, err := n.Repo.Config() if err != nil { return nil, err } return cfg.BootstrapPeers() } type ConstructPeerHostOpts struct { AddrsFactory p2pbhost.AddrsFactory DisableNatPortMap bool DisableRelay bool EnableRelayHop bool ConnectionManager connmgr.ConnManager }