plugins: introduce PluginDaemonInternal to directly interact with IpfsNode

上级 b8ec598d
...@@ -19,7 +19,6 @@ import ( ...@@ -19,7 +19,6 @@ import (
oldcmds "github.com/ipfs/go-ipfs/commands" oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core" "github.com/ipfs/go-ipfs/core"
commands "github.com/ipfs/go-ipfs/core/commands" commands "github.com/ipfs/go-ipfs/core/commands"
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"
libp2p "github.com/ipfs/go-ipfs/core/node/libp2p" libp2p "github.com/ipfs/go-ipfs/core/node/libp2p"
...@@ -368,11 +367,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment ...@@ -368,11 +367,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
// Start "core" plugins. We want to do this *before* starting the HTTP // Start "core" plugins. We want to do this *before* starting the HTTP
// API as the user may be relying on these plugins. // API as the user may be relying on these plugins.
api, err := coreapi.NewCoreAPI(node) err = cctx.Plugins.Start(node)
if err != nil {
return err
}
err = cctx.Plugins.Start(api)
if err != nil { if err != nil {
return err return err
} }
......
package plugin
import "github.com/ipfs/go-ipfs/core"
// PluginDaemonInternal is an interface for daemon plugins. These plugins will be run on
// the daemon and will be given a direct access to the IpfsNode.
//
// Note: PluginDaemonInternal is considered internal and no guarantee is made concerning
// the stability of its API. If you can, use PluginAPI instead.
type PluginDaemonInternal interface {
Plugin
Start(*core.IpfsNode) error
}
...@@ -9,13 +9,15 @@ import ( ...@@ -9,13 +9,15 @@ import (
config "github.com/ipfs/go-ipfs-config" config "github.com/ipfs/go-ipfs-config"
cserialize "github.com/ipfs/go-ipfs-config/serialize" cserialize "github.com/ipfs/go-ipfs-config/serialize"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
coredag "github.com/ipfs/go-ipfs/core/coredag" coredag "github.com/ipfs/go-ipfs/core/coredag"
plugin "github.com/ipfs/go-ipfs/plugin" plugin "github.com/ipfs/go-ipfs/plugin"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo" fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
ipld "github.com/ipfs/go-ipld-format" ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
coreiface "github.com/ipfs/interface-go-ipfs-core"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
) )
...@@ -236,10 +238,14 @@ func (loader *PluginLoader) Inject() error { ...@@ -236,10 +238,14 @@ func (loader *PluginLoader) Inject() error {
} }
// Start starts all long-running plugins. // Start starts all long-running plugins.
func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error { func (loader *PluginLoader) Start(node *core.IpfsNode) error {
if err := loader.transition(loaderInjected, loaderStarting); err != nil { if err := loader.transition(loaderInjected, loaderStarting); err != nil {
return err return err
} }
iface, err := coreapi.NewCoreAPI(node)
if err != nil {
return err
}
for _, pl := range loader.plugins { for _, pl := range loader.plugins {
if pl, ok := pl.(plugin.PluginDaemon); ok { if pl, ok := pl.(plugin.PluginDaemon); ok {
err := pl.Start(iface) err := pl.Start(iface)
...@@ -249,6 +255,14 @@ func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error { ...@@ -249,6 +255,14 @@ func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error {
} }
loader.started = append(loader.started, pl) loader.started = append(loader.started, pl)
} }
if pl, ok := pl.(plugin.PluginDaemonInternal); ok {
err := pl.Start(node)
if err != nil {
_ = loader.Close()
return err
}
loader.started = append(loader.started, pl)
}
} }
return loader.transition(loaderStarting, loaderStarted) return loader.transition(loaderStarting, loaderStarted)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论