提交 da473d28 作者: Łukasz Magiera

constructor: move libp2p related stuff to subpackage

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 cc2d66ff
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
coreapi "github.com/ipfs/go-ipfs/core/coreapi" coreapi "github.com/ipfs/go-ipfs/core/coreapi"
corehttp "github.com/ipfs/go-ipfs/core/corehttp" corehttp "github.com/ipfs/go-ipfs/core/corehttp"
corerepo "github.com/ipfs/go-ipfs/core/corerepo" corerepo "github.com/ipfs/go-ipfs/core/corerepo"
"github.com/ipfs/go-ipfs/core/node" libp2p "github.com/ipfs/go-ipfs/core/node/libp2p"
nodeMount "github.com/ipfs/go-ipfs/fuse/node" nodeMount "github.com/ipfs/go-ipfs/fuse/node"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations" migrate "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
...@@ -324,11 +324,11 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment ...@@ -324,11 +324,11 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
case routingOptionSupernodeKwd: case routingOptionSupernodeKwd:
return errors.New("supernode routing was never fully implemented and has been removed") return errors.New("supernode routing was never fully implemented and has been removed")
case routingOptionDHTClientKwd: case routingOptionDHTClientKwd:
ncfg.Routing = node.DHTClientOption ncfg.Routing = libp2p.DHTClientOption
case routingOptionDHTKwd: case routingOptionDHTKwd:
ncfg.Routing = node.DHTOption ncfg.Routing = libp2p.DHTOption
case routingOptionNoneKwd: case routingOptionNoneKwd:
ncfg.Routing = node.NilRouterOption ncfg.Routing = libp2p.NilRouterOption
default: default:
return fmt.Errorf("unrecognized routing option: %s", routingOption) return fmt.Errorf("unrecognized routing option: %s", routingOption)
} }
......
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
version "github.com/ipfs/go-ipfs" version "github.com/ipfs/go-ipfs"
"github.com/ipfs/go-ipfs/core/bootstrap" "github.com/ipfs/go-ipfs/core/bootstrap"
"github.com/ipfs/go-ipfs/core/node" "github.com/ipfs/go-ipfs/core/node"
"github.com/ipfs/go-ipfs/core/node/libp2p"
rp "github.com/ipfs/go-ipfs/exchange/reprovide" rp "github.com/ipfs/go-ipfs/exchange/reprovide"
"github.com/ipfs/go-ipfs/filestore" "github.com/ipfs/go-ipfs/filestore"
"github.com/ipfs/go-ipfs/fuse/mount" "github.com/ipfs/go-ipfs/fuse/mount"
...@@ -68,10 +69,10 @@ type IpfsNode struct { ...@@ -68,10 +69,10 @@ type IpfsNode struct {
Repo repo.Repo Repo repo.Repo
// Local node // Local node
Pinning pin.Pinner // the pinning manager Pinning pin.Pinner // the pinning manager
Mounts Mounts `optional:"true"` // current mount state, if any. Mounts Mounts `optional:"true"` // current mount state, if any.
PrivateKey ic.PrivKey // the local node's private Key PrivateKey ic.PrivKey // the local node's private Key
PNetFingerprint node.PNetFingerprint `optional:"true"` // fingerprint of private network PNetFingerprint libp2p.PNetFingerprint `optional:"true"` // fingerprint of private network
// Services // Services
Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances Peerstore pstore.Peerstore `optional:"true"` // storage for other Peer instances
......
...@@ -2,21 +2,21 @@ package coremock ...@@ -2,21 +2,21 @@ package coremock
import ( import (
"context" "context"
libp2p2 "github.com/ipfs/go-ipfs/core/node/libp2p"
commands "github.com/ipfs/go-ipfs/commands" "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/node"
"github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo"
datastore "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
syncds "github.com/ipfs/go-datastore/sync" syncds "github.com/ipfs/go-datastore/sync"
config "github.com/ipfs/go-ipfs-config" config "github.com/ipfs/go-ipfs-config"
libp2p "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
host "github.com/libp2p/go-libp2p-host" host "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore" pstore "github.com/libp2p/go-libp2p-peerstore"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
testutil "github.com/libp2p/go-testutil" "github.com/libp2p/go-testutil"
) )
// NewMockNode constructs an IpfsNode for use in tests. // NewMockNode constructs an IpfsNode for use in tests.
...@@ -30,7 +30,7 @@ func NewMockNode() (*core.IpfsNode, error) { ...@@ -30,7 +30,7 @@ func NewMockNode() (*core.IpfsNode, error) {
}) })
} }
func MockHostOption(mn mocknet.Mocknet) node.HostOption { func MockHostOption(mn mocknet.Mocknet) libp2p2.HostOption {
return func(ctx context.Context, id peer.ID, ps pstore.Peerstore, _ ...libp2p.Option) (host.Host, error) { return func(ctx context.Context, id peer.ID, ps pstore.Peerstore, _ ...libp2p.Option) (host.Host, error) {
return mn.AddPeerWithPeerstore(id, ps) return mn.AddPeerWithPeerstore(id, ps)
} }
......
...@@ -8,15 +8,20 @@ import ( ...@@ -8,15 +8,20 @@ import (
"go.uber.org/fx" "go.uber.org/fx"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/core/node/libp2p"
"github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
dsync "github.com/ipfs/go-datastore/sync" dsync "github.com/ipfs/go-datastore/sync"
cfg "github.com/ipfs/go-ipfs-config" cfg "github.com/ipfs/go-ipfs-config"
logging "github.com/ipfs/go-log"
ci "github.com/libp2p/go-libp2p-crypto" ci "github.com/libp2p/go-libp2p-crypto"
peer "github.com/libp2p/go-libp2p-peer" peer "github.com/libp2p/go-libp2p-peer"
) )
var log = logging.Logger("node")
type BuildCfg struct { type BuildCfg struct {
// If online is set, the node will have networking enabled // If online is set, the node will have networking enabled
Online bool Online bool
...@@ -35,8 +40,8 @@ type BuildCfg struct { ...@@ -35,8 +40,8 @@ type BuildCfg struct {
// If NilRepo is set, a Repo backed by a nil datastore will be constructed // If NilRepo is set, a Repo backed by a nil datastore will be constructed
NilRepo bool NilRepo bool
Routing RoutingOption Routing libp2p.RoutingOption
Host HostOption Host libp2p.HostOption
Repo repo.Repo Repo repo.Repo
} }
...@@ -68,11 +73,11 @@ func (cfg *BuildCfg) fillDefaults() error { ...@@ -68,11 +73,11 @@ func (cfg *BuildCfg) fillDefaults() error {
} }
if cfg.Routing == nil { if cfg.Routing == nil {
cfg.Routing = DHTOption cfg.Routing = libp2p.DHTOption
} }
if cfg.Host == nil { if cfg.Host == nil {
cfg.Host = DefaultHostOption cfg.Host = libp2p.DefaultHostOption
} }
return nil return nil
...@@ -94,15 +99,15 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option { ...@@ -94,15 +99,15 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option {
return cfg.Repo return cfg.Repo
}) })
metricsCtx := fx.Provide(func() MetricsCtx { metricsCtx := fx.Provide(func() helpers.MetricsCtx {
return MetricsCtx(ctx) return helpers.MetricsCtx(ctx)
}) })
hostOption := fx.Provide(func() HostOption { hostOption := fx.Provide(func() libp2p.HostOption {
return cfg.Host return cfg.Host
}) })
routingOption := fx.Provide(func() RoutingOption { routingOption := fx.Provide(func() libp2p.RoutingOption {
return cfg.Routing return cfg.Routing
}) })
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/pin" "github.com/ipfs/go-ipfs/pin"
"github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo"
...@@ -54,9 +55,9 @@ func DagCtor(bs blockservice.BlockService) format.DAGService { ...@@ -54,9 +55,9 @@ func DagCtor(bs blockservice.BlockService) format.DAGService {
return merkledag.NewDAGService(bs) return merkledag.NewDAGService(bs)
} }
func OnlineExchangeCtor(mctx MetricsCtx, lc fx.Lifecycle, host host.Host, rt routing.IpfsRouting, bs blockstore.GCBlockstore) exchange.Interface { func OnlineExchangeCtor(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt routing.IpfsRouting, bs blockstore.GCBlockstore) exchange.Interface {
bitswapNetwork := network.NewFromIpfsHost(host, rt) bitswapNetwork := network.NewFromIpfsHost(host, rt)
exch := bitswap.New(lifecycleCtx(mctx, lc), bitswapNetwork, bs) exch := bitswap.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, bs)
lc.Append(fx.Hook{ lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error { OnStop: func(ctx context.Context) error {
return exch.Close() return exch.Close()
...@@ -65,7 +66,7 @@ func OnlineExchangeCtor(mctx MetricsCtx, lc fx.Lifecycle, host host.Host, rt rou ...@@ -65,7 +66,7 @@ func OnlineExchangeCtor(mctx MetricsCtx, lc fx.Lifecycle, host host.Host, rt rou
return exch return exch
} }
func Files(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGService) (*mfs.Root, error) { func Files(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGService) (*mfs.Root, error) {
dsk := datastore.NewKey("/local/filesroot") dsk := datastore.NewKey("/local/filesroot")
pf := func(ctx context.Context, c cid.Cid) error { pf := func(ctx context.Context, c cid.Cid) error {
return repo.Datastore().Put(dsk, c.Bytes()) return repo.Datastore().Put(dsk, c.Bytes())
...@@ -73,7 +74,7 @@ func Files(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGServi ...@@ -73,7 +74,7 @@ func Files(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGServi
var nd *merkledag.ProtoNode var nd *merkledag.ProtoNode
val, err := repo.Datastore().Get(dsk) val, err := repo.Datastore().Get(dsk)
ctx := lifecycleCtx(mctx, lc) ctx := helpers.LifecycleCtx(mctx, lc)
switch { switch {
case err == datastore.ErrNotFound || val == nil: case err == datastore.ErrNotFound || val == nil:
...@@ -114,4 +115,3 @@ func Files(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGServi ...@@ -114,4 +115,3 @@ func Files(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGServi
return root, err return root, err
} }
type MetricsCtx context.Context
...@@ -3,6 +3,7 @@ package node ...@@ -3,6 +3,7 @@ package node
import ( import (
"context" "context"
"github.com/ipfs/go-ipfs/core/node/libp2p"
"github.com/ipfs/go-ipfs/p2p" "github.com/ipfs/go-ipfs/p2p"
"github.com/ipfs/go-ipfs/provider" "github.com/ipfs/go-ipfs/provider"
...@@ -13,38 +14,38 @@ import ( ...@@ -13,38 +14,38 @@ import (
) )
var BaseLibP2P = fx.Options( var BaseLibP2P = fx.Options(
fx.Provide(P2PAddrFilters), fx.Provide(libp2p.P2PAddrFilters),
fx.Provide(P2PBandwidthCounter), fx.Provide(libp2p.P2PBandwidthCounter),
fx.Provide(P2PPNet), fx.Provide(libp2p.P2PPNet),
fx.Provide(P2PAddrsFactory), fx.Provide(libp2p.P2PAddrsFactory),
fx.Provide(P2PConnectionManager), fx.Provide(libp2p.P2PConnectionManager),
fx.Provide(P2PNatPortMap), fx.Provide(libp2p.P2PNatPortMap),
fx.Provide(P2PRelay), fx.Provide(libp2p.P2PRelay),
fx.Provide(P2PAutoRealy), fx.Provide(libp2p.P2PAutoRealy),
fx.Provide(P2PDefaultTransports), fx.Provide(libp2p.P2PDefaultTransports),
fx.Provide(P2PQUIC), fx.Provide(libp2p.P2PQUIC),
fx.Provide(P2PHost), fx.Provide(libp2p.P2PHost),
fx.Provide(NewDiscoveryHandler), fx.Provide(libp2p.NewDiscoveryHandler),
fx.Invoke(AutoNATService), fx.Invoke(libp2p.AutoNATService),
fx.Invoke(P2PPNetChecker), fx.Invoke(libp2p.P2PPNetChecker),
fx.Invoke(StartListening), fx.Invoke(libp2p.StartListening),
fx.Invoke(SetupDiscovery), fx.Invoke(libp2p.SetupDiscovery),
) )
func LibP2P(cfg *BuildCfg) fx.Option { func LibP2P(cfg *BuildCfg) fx.Option {
opts := fx.Options( opts := fx.Options(
BaseLibP2P, BaseLibP2P,
fx.Provide(P2PSecurity(!cfg.DisableEncryptedConnections)), fx.Provide(libp2p.P2PSecurity(!cfg.DisableEncryptedConnections)),
maybeProvide(Pubsub, cfg.getOpt("pubsub") || cfg.getOpt("ipnsps")), maybeProvide(libp2p.Pubsub, cfg.getOpt("pubsub") || cfg.getOpt("ipnsps")),
fx.Provide(P2PSmuxTransport(cfg.getOpt("mplex"))), fx.Provide(libp2p.P2PSmuxTransport(cfg.getOpt("mplex"))),
fx.Provide(P2PRouting), fx.Provide(libp2p.P2PRouting),
fx.Provide(P2PBaseRouting), fx.Provide(libp2p.P2PBaseRouting),
maybeProvide(P2PPubsubRouter, cfg.getOpt("ipnsps")), maybeProvide(libp2p.P2PPubsubRouter, cfg.getOpt("ipnsps")),
) )
return opts return opts
...@@ -62,7 +63,7 @@ func Storage(cfg *BuildCfg) fx.Option { ...@@ -62,7 +63,7 @@ func Storage(cfg *BuildCfg) fx.Option {
var Identity = fx.Options( var Identity = fx.Options(
fx.Provide(PeerID), fx.Provide(PeerID),
fx.Provide(PrivateKey), fx.Provide(PrivateKey),
fx.Provide(Peerstore), fx.Provide(libp2p.Peerstore),
) )
var IPNS = fx.Options( var IPNS = fx.Options(
......
...@@ -10,21 +10,6 @@ import ( ...@@ -10,21 +10,6 @@ import (
"go.uber.org/fx" "go.uber.org/fx"
) )
// lifecycleCtx creates a context which will be cancelled when lifecycle stops
//
// This is a hack which we need because most of our services use contexts in a
// wrong way
func lifecycleCtx(mctx MetricsCtx, lc fx.Lifecycle) context.Context {
ctx, cancel := context.WithCancel(mctx)
lc.Append(fx.Hook{
OnStop: func(_ context.Context) error {
cancel()
return nil
},
})
return ctx
}
type lcProcess struct { type lcProcess struct {
fx.In fx.In
......
package helpers
import (
"context"
"go.uber.org/fx"
)
type MetricsCtx context.Context
// LifecycleCtx creates a context which will be cancelled when lifecycle stops
//
// This is a hack which we need because most of our services use contexts in a
// wrong way
func LifecycleCtx(mctx MetricsCtx, lc fx.Lifecycle) context.Context {
ctx, cancel := context.WithCancel(mctx)
lc.Append(fx.Hook{
OnStop: func(_ context.Context) error {
cancel()
return nil
},
})
return ctx
}
package node package libp2p
import ( import (
"context" "context"
"time" "time"
"github.com/ipfs/go-ipfs-config" "github.com/ipfs/go-ipfs-config"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/libp2p/go-libp2p-host" "github.com/libp2p/go-libp2p-host"
"github.com/libp2p/go-libp2p-peerstore" "github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p/p2p/discovery" "github.com/libp2p/go-libp2p/p2p/discovery"
...@@ -27,20 +28,20 @@ func (dh *discoveryHandler) HandlePeerFound(p peerstore.PeerInfo) { ...@@ -27,20 +28,20 @@ func (dh *discoveryHandler) HandlePeerFound(p peerstore.PeerInfo) {
} }
} }
func NewDiscoveryHandler(mctx MetricsCtx, lc fx.Lifecycle, host host.Host) *discoveryHandler { func NewDiscoveryHandler(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) *discoveryHandler {
return &discoveryHandler{ return &discoveryHandler{
ctx: lifecycleCtx(mctx, lc), ctx: helpers.LifecycleCtx(mctx, lc),
host: host, host: host,
} }
} }
func SetupDiscovery(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host host.Host, handler *discoveryHandler) error { func SetupDiscovery(mctx helpers.MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host host.Host, handler *discoveryHandler) error {
if cfg.Discovery.MDNS.Enabled { if cfg.Discovery.MDNS.Enabled {
mdns := cfg.Discovery.MDNS mdns := cfg.Discovery.MDNS
if mdns.Interval == 0 { if mdns.Interval == 0 {
mdns.Interval = 5 mdns.Interval = 5
} }
service, err := discovery.NewMdnsService(lifecycleCtx(mctx, lc), host, time.Duration(mdns.Interval)*time.Second, discovery.ServiceTag) service, err := discovery.NewMdnsService(helpers.LifecycleCtx(mctx, lc), host, time.Duration(mdns.Interval)*time.Second, discovery.ServiceTag)
if err != nil { if err != nil {
log.Error("mdns error: ", err) log.Error("mdns error: ", err)
return nil return nil
......
package node package libp2p
import ( import (
"bytes" "bytes"
...@@ -45,10 +45,11 @@ import ( ...@@ -45,10 +45,11 @@ import (
mamask "github.com/whyrusleeping/multiaddr-filter" mamask "github.com/whyrusleeping/multiaddr-filter"
"go.uber.org/fx" "go.uber.org/fx"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo"
) )
var log = logging.Logger("node") var log = logging.Logger("p2pnode")
type HostOption func(ctx context.Context, id peer.ID, ps peerstore.Peerstore, options ...libp2p.Option) (host.Host, error) type HostOption func(ctx context.Context, id peer.ID, ps peerstore.Peerstore, options ...libp2p.Option) (host.Host, error)
type RoutingOption func(context.Context, host.Host, datastore.Batching, record.Validator) (routing.IpfsRouting, error) type RoutingOption func(context.Context, host.Host, datastore.Batching, record.Validator) (routing.IpfsRouting, error)
...@@ -396,13 +397,13 @@ type P2PHostOut struct { ...@@ -396,13 +397,13 @@ type P2PHostOut struct {
Routing BaseRouting Routing BaseRouting
} }
func P2PHost(mctx MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut, err error) { func P2PHost(mctx helpers.MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut, err error) {
opts := []libp2p.Option{libp2p.NoListenAddrs} opts := []libp2p.Option{libp2p.NoListenAddrs}
for _, o := range params.Opts { for _, o := range params.Opts {
opts = append(opts, o...) opts = append(opts, o...)
} }
ctx := lifecycleCtx(mctx, lc) ctx := helpers.LifecycleCtx(mctx, lc)
opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) { opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
r, err := params.RoutingOption(ctx, h, params.Repo.Datastore(), params.Validator) r, err := params.RoutingOption(ctx, h, params.Repo.Datastore(), params.Validator)
...@@ -501,9 +502,9 @@ type p2pPSRoutingIn struct { ...@@ -501,9 +502,9 @@ type p2pPSRoutingIn struct {
PubSub *pubsub.PubSub `optional:"true"` PubSub *pubsub.PubSub `optional:"true"`
} }
func P2PPubsubRouter(mctx MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) (p2pRouterOut, *namesys.PubsubValueStore) { func P2PPubsubRouter(mctx helpers.MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) (p2pRouterOut, *namesys.PubsubValueStore) {
psRouter := namesys.NewPubsubValueStore( psRouter := namesys.NewPubsubValueStore(
lifecycleCtx(mctx, lc), helpers.LifecycleCtx(mctx, lc),
in.Host, in.Host,
in.BaseRouting, in.BaseRouting,
in.PubSub, in.PubSub,
...@@ -523,7 +524,7 @@ func P2PPubsubRouter(mctx MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) (p2pRo ...@@ -523,7 +524,7 @@ func P2PPubsubRouter(mctx MetricsCtx, lc fx.Lifecycle, in p2pPSRoutingIn) (p2pRo
}, psRouter }, psRouter
} }
func AutoNATService(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host host.Host) error { func AutoNATService(mctx helpers.MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host host.Host) error {
if !cfg.Swarm.EnableAutoNATService { if !cfg.Swarm.EnableAutoNATService {
return nil return nil
} }
...@@ -532,11 +533,11 @@ func AutoNATService(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host h ...@@ -532,11 +533,11 @@ func AutoNATService(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, host h
opts = append(opts, libp2p.DefaultTransports, libp2p.Transport(libp2pquic.NewTransport)) opts = append(opts, libp2p.DefaultTransports, libp2p.Transport(libp2pquic.NewTransport))
} }
_, err := autonat.NewAutoNATService(lifecycleCtx(mctx, lc), host, opts...) _, err := autonat.NewAutoNATService(helpers.LifecycleCtx(mctx, lc), host, opts...)
return err return err
} }
func Pubsub(mctx MetricsCtx, lc fx.Lifecycle, host host.Host, cfg *config.Config) (service *pubsub.PubSub, err error) { func Pubsub(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, cfg *config.Config) (service *pubsub.PubSub, err error) {
var pubsubOptions []pubsub.Option var pubsubOptions []pubsub.Option
if cfg.Pubsub.DisableSigning { if cfg.Pubsub.DisableSigning {
pubsubOptions = append(pubsubOptions, pubsub.WithMessageSigning(false)) pubsubOptions = append(pubsubOptions, pubsub.WithMessageSigning(false))
...@@ -550,10 +551,10 @@ func Pubsub(mctx MetricsCtx, lc fx.Lifecycle, host host.Host, cfg *config.Config ...@@ -550,10 +551,10 @@ func Pubsub(mctx MetricsCtx, lc fx.Lifecycle, host host.Host, cfg *config.Config
case "": case "":
fallthrough fallthrough
case "floodsub": case "floodsub":
service, err = pubsub.NewFloodSub(lifecycleCtx(mctx, lc), host, pubsubOptions...) service, err = pubsub.NewFloodSub(helpers.LifecycleCtx(mctx, lc), host, pubsubOptions...)
case "gossipsub": case "gossipsub":
service, err = pubsub.NewGossipSub(lifecycleCtx(mctx, lc), host, pubsubOptions...) service, err = pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, pubsubOptions...)
default: default:
err = fmt.Errorf("Unknown pubsub router %s", cfg.Pubsub.Router) err = fmt.Errorf("Unknown pubsub router %s", cfg.Pubsub.Router)
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/libp2p/go-libp2p-routing" "github.com/libp2p/go-libp2p-routing"
"go.uber.org/fx" "go.uber.org/fx"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/exchange/reprovide" "github.com/ipfs/go-ipfs/exchange/reprovide"
"github.com/ipfs/go-ipfs/pin" "github.com/ipfs/go-ipfs/pin"
"github.com/ipfs/go-ipfs/provider" "github.com/ipfs/go-ipfs/provider"
...@@ -18,12 +19,12 @@ import ( ...@@ -18,12 +19,12 @@ import (
const kReprovideFrequency = time.Hour * 12 const kReprovideFrequency = time.Hour * 12
func ProviderQueue(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (*provider.Queue, error) { func ProviderQueue(mctx helpers.MetricsCtx, lc fx.Lifecycle, repo repo.Repo) (*provider.Queue, error) {
return provider.NewQueue(lifecycleCtx(mctx, lc), "provider-v1", repo.Datastore()) return provider.NewQueue(helpers.LifecycleCtx(mctx, lc), "provider-v1", repo.Datastore())
} }
func ProviderCtor(mctx MetricsCtx, lc fx.Lifecycle, queue *provider.Queue, rt routing.IpfsRouting) provider.Provider { func ProviderCtor(mctx helpers.MetricsCtx, lc fx.Lifecycle, queue *provider.Queue, rt routing.IpfsRouting) provider.Provider {
p := provider.NewProvider(lifecycleCtx(mctx, lc), queue, rt) p := provider.NewProvider(helpers.LifecycleCtx(mctx, lc), queue, rt)
lc.Append(fx.Hook{ lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error { OnStart: func(ctx context.Context) error {
...@@ -38,7 +39,7 @@ func ProviderCtor(mctx MetricsCtx, lc fx.Lifecycle, queue *provider.Queue, rt ro ...@@ -38,7 +39,7 @@ func ProviderCtor(mctx MetricsCtx, lc fx.Lifecycle, queue *provider.Queue, rt ro
return p return p
} }
func ReproviderCtor(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, bs BaseBlocks, ds format.DAGService, pinning pin.Pinner, rt routing.IpfsRouting) (*reprovide.Reprovider, error) { func ReproviderCtor(mctx helpers.MetricsCtx, lc fx.Lifecycle, cfg *config.Config, bs BaseBlocks, ds format.DAGService, pinning pin.Pinner, rt routing.IpfsRouting) (*reprovide.Reprovider, error) {
var keyProvider reprovide.KeyChanFunc var keyProvider reprovide.KeyChanFunc
switch cfg.Reprovider.Strategy { switch cfg.Reprovider.Strategy {
...@@ -53,7 +54,7 @@ func ReproviderCtor(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, bs Bas ...@@ -53,7 +54,7 @@ func ReproviderCtor(mctx MetricsCtx, lc fx.Lifecycle, cfg *config.Config, bs Bas
default: default:
return nil, fmt.Errorf("unknown reprovider strategy '%s'", cfg.Reprovider.Strategy) return nil, fmt.Errorf("unknown reprovider strategy '%s'", cfg.Reprovider.Strategy)
} }
return reprovide.NewReprovider(lifecycleCtx(mctx, lc), rt, keyProvider), nil return reprovide.NewReprovider(helpers.LifecycleCtx(mctx, lc), rt, keyProvider), nil
} }
func Reprovider(cfg *config.Config, reprovider *reprovide.Reprovider) error { func Reprovider(cfg *config.Config, reprovider *reprovide.Reprovider) error {
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
config "github.com/ipfs/go-ipfs-config" config "github.com/ipfs/go-ipfs-config"
"go.uber.org/fx" "go.uber.org/fx"
"github.com/ipfs/go-ipfs/core/node/helpers"
"github.com/ipfs/go-ipfs/filestore" "github.com/ipfs/go-ipfs/filestore"
"github.com/ipfs/go-ipfs/repo" "github.com/ipfs/go-ipfs/repo"
"github.com/ipfs/go-ipfs/thirdparty/cidv0v1" "github.com/ipfs/go-ipfs/thirdparty/cidv0v1"
...@@ -37,8 +38,8 @@ func DatastoreCtor(repo repo.Repo) datastore.Datastore { ...@@ -37,8 +38,8 @@ func DatastoreCtor(repo repo.Repo) datastore.Datastore {
type BaseBlocks blockstore.Blockstore type BaseBlocks blockstore.Blockstore
func BaseBlockstoreCtor(permanent bool, nilRepo bool) func(mctx MetricsCtx, repo repo.Repo, cfg *config.Config, lc fx.Lifecycle) (bs BaseBlocks, err error) { func BaseBlockstoreCtor(permanent bool, nilRepo bool) func(mctx helpers.MetricsCtx, repo repo.Repo, cfg *config.Config, lc fx.Lifecycle) (bs BaseBlocks, err error) {
return func(mctx MetricsCtx, repo repo.Repo, cfg *config.Config, lc fx.Lifecycle) (bs BaseBlocks, err error) { return func(mctx helpers.MetricsCtx, repo repo.Repo, cfg *config.Config, lc fx.Lifecycle) (bs BaseBlocks, err error) {
rds := &retrystore.Datastore{ rds := &retrystore.Datastore{
Batching: repo.Datastore(), Batching: repo.Datastore(),
Delay: time.Millisecond * 200, Delay: time.Millisecond * 200,
......
...@@ -6,11 +6,10 @@ import ( ...@@ -6,11 +6,10 @@ import (
"testing" "testing"
"github.com/ipfs/go-block-format" "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/mock" "github.com/ipfs/go-ipfs/core/mock"
"github.com/ipfs/go-ipfs/core/node" "github.com/ipfs/go-ipfs/core/node/libp2p"
cid "github.com/ipfs/go-cid"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
) )
...@@ -27,7 +26,7 @@ func TestBitswapWithoutRouting(t *testing.T) { ...@@ -27,7 +26,7 @@ func TestBitswapWithoutRouting(t *testing.T) {
n, err := core.NewNode(ctx, &core.BuildCfg{ n, err := core.NewNode(ctx, &core.BuildCfg{
Online: true, Online: true,
Host: coremock.MockHostOption(mn), Host: coremock.MockHostOption(mn),
Routing: node.NilRouterOption, // no routing Routing: libp2p.NilRouterOption, // no routing
}) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论