Skip to content

Commit

Permalink
feat(config.Store): support store options to enable ipfs api & pubsub
Browse files Browse the repository at this point in the history
this adds a new "Options" object to store configuration, which after recent upgrades to github.com/qri-io/cafs/ipfs, supports configuring qri's IPFS node to enable the IPFS HTTP API and optionally support for pubsub.

To enable both, config.yaml's `store` should now look like this:

```yaml
store
  type: "ipfs"
  options:
    api: true
    pubsub: true
```

if `store.options.api` is set to `true` it will use the IPFS config to figure out what address to bind the api to (in ipfs that defaults to localhost:5001).

with both api and pubsub activated, it's possible to talk to the underlying pubsub api by supplying an `--api` flag to the go-ipfs binary (version 0.4.18 or higher). after running `qri connect`, in another terminal: `ipfs --api /ip4/127.0.0.1/tcp/5001/ pubsub sub foo` should hang. in a third terminal `ipfs --api /ip4/127.0.0.1/tcp/5001/ pubsub pub foo bar` will publish to the second terminal. fun! This `--api` flag trick should work for most ipfs commands.

closes #162, closes #658
  • Loading branch information
b5 committed Jan 22, 2019
1 parent 0064715 commit e76b9f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 10 additions & 4 deletions cmd/qri.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ func (o *QriOptions) Init() (err error) {
}

var fs *ipfs.Filestore
fs, err = ipfs.NewFilestore(func(cfg *ipfs.StoreCfg) {
cfg.FsRepoPath = o.ipfsFsPath
// cfg.Online = online
})

fsOpts := []ipfs.Option{
func(cfg *ipfs.StoreCfg) {
cfg.FsRepoPath = o.ipfsFsPath
// cfg.Online = online
},
ipfs.OptsFromMap(o.config.Store.Options),
}

fs, err = ipfs.NewFilestore(fsOpts...)
if err != nil {
return
}
Expand Down
9 changes: 7 additions & 2 deletions config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import "github.com/qri-io/jsonschema"

// Store configures a qri content addessed file store (cafs)
type Store struct {
Type string `json:"type"`
Type string `json:"type"`
Options map[string]interface{} `json:"options,omitempty"`
}

// DefaultStore returns a new default Store configuration
func DefaultStore() *Store {
return &Store{
Type: "ipfs",
Options: map[string]interface{}{
"api": true,
},
}
}

Expand Down Expand Up @@ -38,7 +42,8 @@ func (cfg Store) Validate() error {
// Copy returns a deep copy of the Store struct
func (cfg *Store) Copy() *Store {
res := &Store{
Type: cfg.Type,
Type: cfg.Type,
Options: cfg.Options,
}

return res
Expand Down

0 comments on commit e76b9f8

Please sign in to comment.