Skip to content

Commit

Permalink
plugins: introduce PluginDaemonInternal to directly interact with Ipf…
Browse files Browse the repository at this point in the history
…sNode
  • Loading branch information
MichaelMure committed Nov 22, 2019
1 parent b8ec598 commit 2a9e500
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
7 changes: 1 addition & 6 deletions cmd/ipfs/daemon.go
Expand Up @@ -19,7 +19,6 @@ import (
oldcmds "github.com/ipfs/go-ipfs/commands"
"github.com/ipfs/go-ipfs/core"
commands "github.com/ipfs/go-ipfs/core/commands"
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
libp2p "github.com/ipfs/go-ipfs/core/node/libp2p"
Expand Down Expand Up @@ -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
// API as the user may be relying on these plugins.
api, err := coreapi.NewCoreAPI(node)
if err != nil {
return err
}
err = cctx.Plugins.Start(api)
err = cctx.Plugins.Start(node)
if err != nil {
return err
}
Expand Down
14 changes: 14 additions & 0 deletions plugin/daemoninternal.go
@@ -0,0 +1,14 @@
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
}
18 changes: 16 additions & 2 deletions plugin/loader/loader.go
Expand Up @@ -9,13 +9,15 @@ import (

config "github.com/ipfs/go-ipfs-config"
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"
plugin "github.com/ipfs/go-ipfs/plugin"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"

ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log"
coreiface "github.com/ipfs/interface-go-ipfs-core"
opentracing "github.com/opentracing/opentracing-go"
)

Expand Down Expand Up @@ -236,10 +238,14 @@ func (loader *PluginLoader) Inject() error {
}

// 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 {
return err
}
iface, err := coreapi.NewCoreAPI(node)
if err != nil {
return err
}
for _, pl := range loader.plugins {
if pl, ok := pl.(plugin.PluginDaemon); ok {
err := pl.Start(iface)
Expand All @@ -249,6 +255,14 @@ func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error {
}
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)
Expand Down

0 comments on commit 2a9e500

Please sign in to comment.