plugins.md 5.59 KB
Newer Older
1 2
# Plugins

Jeromy Johnson's avatar
Jeromy Johnson committed
3 4
Since 0.4.11 go-ipfs has an experimental plugin system that allows augmenting
the daemons functionality without recompiling.
5

6
When an IPFS node is started, it will load plugins from the `$IPFS_PATH/plugins`
7 8
directory (by default `~/.ipfs/plugins`).

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
**Table of Contents**

- [Plugin Types](#plugin-types)
    - [IPLD](#ipld)
    - [Datastore](#datastore)
- [Available Plugins](#available-plugins)
- [Installing Plugins](#installing-plugins)
    - [External Plugin](#external-plugin)
        - [In-tree](#in-tree)
        - [Out-of-tree](#out-of-tree)
    - [Preloaded Plugins](#preloaded-plugins)
- [Creating A Plugin](#creating-a-plugin)

## Plugin Types

24 25 26
Plugins can implement one or more plugin types, defined in the
[plugin](https://godoc.org/github.com/ipfs/go-ipfs/plugin) package.

27
### IPLD
28 29 30 31

IPLD plugins add support for additional formats to `ipfs dag` and other IPLD
related commands.

32 33 34 35
### Datastore

Datastore plugins add support for additional datastore backends.

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
### Tracer

(experimental)

Tracer plugins allow injecting an opentracing backend into go-ipfs.

### Daemon

Daemon plugins are started when the go-ipfs daemon is started and are given an
instance of the CoreAPI. This should make it possible to build an ipfs-based
application without IPC and without forking go-ipfs.

Note: We eventually plan to make go-ipfs usable as a library. However, this
plugin type is likely the best interim solution.

51 52 53 54 55 56 57 58 59
### Internal

(never stable)

Internal plugins are like daemon plugins _except_ that they can access, replace,
and modify all internal state. Use this plugin type to extend go-ipfs in
arbitrary ways. However, be aware that your plugin will likely break every time
go-ipfs updated.

Steven Allen's avatar
Steven Allen committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
## Configuration

Plugins can be configured in the `Plugins` section of the config file. Here,
plugins can be:

1. Passed an arbitrary config object via the `Config` field.
2. Disabled via the `Disabled` field.

Example:

```js
{
  // ...
  "Plugins": {
    "Plugins": {
      // plugin named "plugin-foo"
      "plugin-foo": {
        "Config": { /* arbitrary json */ }
      },
      // plugin named "plugin-bar"
      "plugin-bar": {
        "Disabled": true // "plugin-bar" will not be loaded
      }
    }
  }
}
```

88 89
## Available Plugins

90 91 92 93 94 95
| Name                                                                            | Type      | Preloaded | Description                                    |
|---------------------------------------------------------------------------------|-----------|-----------|------------------------------------------------|
| [git](https://github.com/ipfs/go-ipfs/tree/master/plugin/plugins/git)           | IPLD      | x         | An IPLD format for git objects.                |
| [badgerds](https://github.com/ipfs/go-ipfs/tree/master/plugin/plugins/badgerds) | Datastore | x         | A high performance but experimental datastore. |
| [flatfs](https://github.com/ipfs/go-ipfs/tree/master/plugin/plugins/flatfs)     | Datastore | x         | A stable filesystem-based datastore.           |
| [levelds](https://github.com/ipfs/go-ipfs/tree/master/plugin/plugins/levelds)   | Datastore | x         | A stable, flexible datastore backend.          |
Steven Allen's avatar
Steven Allen committed
96
| [jaeger](https://github.com/ipfs/go-jaeger-plugin)                              | Tracing   |           | An opentracing backend.                        |
97

98 99
* **Preloaded** plugins are built into the go-ipfs binary and do not need to be
  installed separately. At the moment, all in-tree plugins are preloaded.
100 101 102

## Installing Plugins

103 104 105 106 107
Go-ipfs supports two types of plugins: External and Preloaded.

* External plugins must be installed in `$IPFS_PATH/plugins/` (usually
`~/.ipfs/plugins/`).
* Preloaded plugins are built-into the go-ipfs when it's compiled.
108 109

### External Plugin
110

111 112 113 114
The advantage of an external plugin is that it can be built, packaged, and
installed independently of go-ipfs. Unfortunately, this method is only supported
on Linux and MacOS at the moment. Users of other operating systems should follow
the instructions for preloaded plugins.
115

116
#### In-tree
117

118 119 120
To build plugins included in
[plugin/plugins](https://github.com/ipfs/go-ipfs/tree/master/plugin/plugins),
run:
121 122 123 124 125 126

```bash
go-ipfs$ make build_plugins
go-ipfs$ ls plugin/plugins/*.so
```

127 128
To install, copy desired plugins to `$IPFS_PATH/plugins`. For example:

129 130 131 132 133 134
```bash
go-ipfs$ mkdir -p ~/.ipfs/plugins/
go-ipfs$ cp plugin/plugins/git.so ~/.ipfs/plugins/
go-ipfs$ chmod +x ~/.ipfs/plugins/git.so # ensure plugin is executable
```

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
Finally, restart daemon if it is running.

#### Out-of-tree

To build out-of-tree plugins, use the plugin's Makefile if provided. Otherwise,
you can manually build the plugin by running:

```bash
myplugin$ go build -buildmode=plugin -i -o myplugin.so myplugin.go
```

Finally, as with in-tree plugins:

1. Install the plugin in `$IPFS_PATH/plugins`.
2. Mark the plugin as executable (`chmod +x $IPFS_PATH/plugins/myplugin.so`).
3. Restart your IPFS daemon (if running).
151

152
### Preloaded Plugins
153

154 155 156 157 158
The advantages of preloaded plugins are:

1. They're bundled with the go-ipfs binary.
2. They work on all platforms.

159
To preload a go-ipfs plugin:
160

161
1. Add the plugin to the preload list: `plugin/loader/preload_list`
162 163 164 165
2. Build ipfs
```bash
go-ipfs$ make build
```
166

167 168 169 170 171 172 173
You can also preload an in-tree but disabled-by-default plugin by adding it to
the IPFS_PLUGINS variable. For example, to enable plugins foo, bar, and baz:

```bash
go-ipfs$ make build IPFS_PLUGINS="foo bar baz"
```

174 175 176 177 178 179
## Creating A Plugin

To create your own out-of-tree plugin, use the [example
plugin](https://github.com/ipfs/go-ipfs-example-plugin/) as a starting point.
When you're ready, submit a PR adding it to the list of [available
plugins](#available-plugins).