plugins: introduce PluginDaemonInternal to directly interact with IpfsNode
Michael Muré committed
Nov 22, 2019 at 13:18 UTC
2a9e5005da1ae517f8e4a0aa69bce5a1d752372b
3 files changed
+31
-8
cmd/ipfs/daemon.go
+1
-6
@@ -19,7 +19,6 @@ import (
19
oldcmds "github.com/ipfs/go-ipfs/commands"
20
"github.com/ipfs/go-ipfs/core"
21
commands "github.com/ipfs/go-ipfs/core/commands"
22
- coreapi "github.com/ipfs/go-ipfs/core/coreapi"
22
corehttp "github.com/ipfs/go-ipfs/core/corehttp"
23
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
24
libp2p "github.com/ipfs/go-ipfs/core/node/libp2p"
@@ -368,11 +367,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
367
368
// Start "core" plugins. We want to do this *before* starting the HTTP
369
// API as the user may be relying on these plugins.
371
- api, err := coreapi.NewCoreAPI(node)
372
- if err != nil {
373
- return err
374
- }
375
- err = cctx.Plugins.Start(api)
370
+ err = cctx.Plugins.Start(node)
371
if err != nil {
372
return err
373
}
plugin/daemoninternal.go
new
+14
@@ -0,0 +1,14 @@
1
+package plugin
2
+
3
+import "github.com/ipfs/go-ipfs/core"
4
+
5
+// PluginDaemonInternal is an interface for daemon plugins. These plugins will be run on
6
+// the daemon and will be given a direct access to the IpfsNode.
7
+//
8
+// Note: PluginDaemonInternal is considered internal and no guarantee is made concerning
9
+// the stability of its API. If you can, use PluginAPI instead.
10
+type PluginDaemonInternal interface {
11
+ Plugin
12
+
13
+ Start(*core.IpfsNode) error
14
+}
plugin/loader/loader.go
+16
-2
@@ -9,13 +9,15 @@ import (
9
10
config "github.com/ipfs/go-ipfs-config"
11
cserialize "github.com/ipfs/go-ipfs-config/serialize"
12
+
13
+ "github.com/ipfs/go-ipfs/core"
14
+ "github.com/ipfs/go-ipfs/core/coreapi"
15
coredag "github.com/ipfs/go-ipfs/core/coredag"
16
plugin "github.com/ipfs/go-ipfs/plugin"
17
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
18
19
ipld "github.com/ipfs/go-ipld-format"
20
logging "github.com/ipfs/go-log"
18
- coreiface "github.com/ipfs/interface-go-ipfs-core"
21
opentracing "github.com/opentracing/opentracing-go"
22
)
23
@@ -236,10 +238,14 @@ func (loader *PluginLoader) Inject() error {
238
}
239
240
// Start starts all long-running plugins.
239
-func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error {
241
+func (loader *PluginLoader) Start(node *core.IpfsNode) error {
242
if err := loader.transition(loaderInjected, loaderStarting); err != nil {
243
return err
244
}
245
+ iface, err := coreapi.NewCoreAPI(node)
246
+ if err != nil {
247
+ return err
248
+ }
249
for _, pl := range loader.plugins {
250
if pl, ok := pl.(plugin.PluginDaemon); ok {
251
err := pl.Start(iface)
@@ -249,6 +255,14 @@ func (loader *PluginLoader) Start(iface coreiface.CoreAPI) error {
255
}
256
loader.started = append(loader.started, pl)
257
}
258
+ if pl, ok := pl.(plugin.PluginDaemonInternal); ok {
259
+ err := pl.Start(node)
260
+ if err != nil {
261
+ _ = loader.Close()
262
+ return err
263
+ }
264
+ loader.started = append(loader.started, pl)
265
+ }
266
}
267
268
return loader.transition(loaderStarting, loaderStarted)