Skip to content

Commit

Permalink
feat: Add enable pubsub/namesys extra opt
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Fanton <guilhem.fanton@gmail.com>
  • Loading branch information
gfanton committed Sep 9, 2020
1 parent d6caf1d commit 0f6b050
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
35 changes: 34 additions & 1 deletion android/bridge/src/main/java/ipfs/gomobile/android/IPFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@ synchronized public void restart() throws NodeStopException {
try { start(); } catch(NodeStartException ignore) { /* Should never happen */ }
}

/**
* Instantiate the ipfs node with the experimental pubsub feature enabled.
*
* @throws ExtraOptionException If enable the extra option failed
* @see <a href="https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-pubsub">Experimental features of IPFS</a>
*/
synchronized public void enablePubsubExperiment() throws ExtraOptionException {
try {
openRepoIfClosed();
repo.enablePubsubExperiment();
} catch (Exception e) {
throw new ExtraOptionException("Enable pubsub experiment failed", e);
}
}

/**
* Enable IPNS record distribution through pubsub; enables pubsub.
*
* @throws ExtraOptionException If enable the extra option failed
* @see <a href="https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipns-pubsub">Experimental features of IPFS</a>
*/
synchronized public void enableNamesysPubsub() throws ExtraOptionException {
try {
openRepoIfClosed();
repo.enableNamesysPubsub();
} catch (Exception e) {
throw new ExtraOptionException("Enable namesys pubsub failed", e);
}
}

/**
* Gets the IPFS instance config as a JSON.
*
Expand Down Expand Up @@ -332,8 +362,11 @@ synchronized private void openRepoIfClosed() throws RepoOpenException {
}
}


// Exceptions
public static class ExtraOptionException extends Exception {
ExtraOptionException(String message, Throwable err) { super(message, err); }
}

public static class ConfigCreationException extends Exception {
ConfigCreationException(String message, Throwable err) { super(message, err); }
}
Expand Down
8 changes: 2 additions & 6 deletions go/bind/core/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,11 @@ func (n *Node) ServeMultiaddr(smaddr string) (string, error) {
func NewNode(r *Repo) (*Node, error) {
ctx := context.Background()

if _, err := loadPlugins(r.path); err != nil {
if _, err := loadPlugins(r.mr.Path); err != nil {
return nil, err
}

repo := &mobile_node.MobileRepo{
Repo: r.irepo,
Path: r.path,
}
mnode, err := mobile_node.NewNode(ctx, repo, &mobile_host.MobileConfig{})
mnode, err := mobile_node.NewNode(ctx, r.mr, &mobile_host.MobileConfig{})
if err != nil {
return nil, err
}
Expand Down
29 changes: 21 additions & 8 deletions go/bind/core/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"path/filepath"

"github.com/ipfs-shipyard/gomobile-ipfs/go/pkg/node"
ipfs_loader "github.com/ipfs/go-ipfs/plugin/loader"
ipfs_repo "github.com/ipfs/go-ipfs/repo"
ipfs_fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
Expand All @@ -11,8 +12,7 @@ import (
var plugins *ipfs_loader.PluginLoader

type Repo struct {
irepo ipfs_repo.Repo
path string
mr *node.MobileRepo
}

func RepoIsInitialized(path string) bool {
Expand All @@ -37,19 +37,32 @@ func OpenRepo(path string) (*Repo, error) {
return nil, err
}

return &Repo{irepo, path}, nil
mRepo := &node.MobileRepo{
Repo: irepo,
Path: path,
}

return &Repo{mRepo}, nil
}

func (r *Repo) EnablePubsubExperiment() {
r.mr.EnablePubsubExperiment = true
}

func (r *Repo) EnableNamesysPubsub() {
r.mr.EnableNamesysPubsub = true
}

func (r *Repo) GetRootPath() string {
return r.path
return r.mr.Path
}

func (r *Repo) SetConfig(c *Config) error {
return r.irepo.SetConfig(c.getConfig())
return r.mr.Repo.SetConfig(c.getConfig())
}

func (r *Repo) GetConfig() (*Config, error) {
cfg, err := r.irepo.Config()
cfg, err := r.mr.Repo.Config()
if err != nil {
return nil, err
}
Expand All @@ -58,11 +71,11 @@ func (r *Repo) GetConfig() (*Config, error) {
}

func (r *Repo) Close() error {
return r.irepo.Close()
return r.mr.Close()
}

func (r *Repo) getRepo() ipfs_repo.Repo {
return r.irepo
return r.mr
}

func loadPlugins(repoPath string) (*ipfs_loader.PluginLoader, error) {
Expand Down
4 changes: 4 additions & 0 deletions go/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func NewNode(ctx context.Context, repo *MobileRepo, mcfg *host.MobileConfig) (*I
NilRepo: false,
Repo: repo,
Host: host.NewMobileHostOption(mcfg),
ExtraOpts: map[string]bool{
"pubsub": repo.EnablePubsubExperiment,
"ipnsps": repo.EnableNamesysPubsub,
},
}

// create ipfs node
Expand Down
6 changes: 3 additions & 3 deletions go/pkg/node/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var _ ipfs_repo.Repo = (*MobileRepo)(nil)
type MobileRepo struct {
ipfs_repo.Repo
Path string
}

func NewMobileRepo(repo ipfs_repo.Repo, path string) *MobileRepo {
return &MobileRepo{repo, path}
// extra config
EnablePubsubExperiment bool
EnableNamesysPubsub bool
}
16 changes: 16 additions & 0 deletions ios/Bridge/GomobileIPFS/Sources/IPFS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ public class IPFS {
try self.start()
}

/// Instantiate the ipfs node with the experimental pubsub feature enabled.
/// - Throws:
/// - `RepoError`: If the opening of the repo failed
public func enablePubsubExperiment() throws {
try openRepoIfClosed()
self.repo!.goRepo.enablePubsubExperiment()
}

/// Enable IPNS record distribution through pubsub; enables pubsub.
/// - Throws:
/// - `RepoError`: If the opening of the repo failed
public func enableNamesysPubsub() throws {
try openRepoIfClosed()
self.repo!.goRepo.enableNamesysPubsub()
}

/// Gets the IPFS instance config as a dict
/// - Throws:
/// - `RepoError`: If the opening of the repo or the getting of its config failed
Expand Down

0 comments on commit 0f6b050

Please sign in to comment.