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 10, 2020
1 parent d6caf1d commit 33af183
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 24 deletions.
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(':bridge')
}
6 changes: 3 additions & 3 deletions android/bridge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ android {

dependencies {
implementation "$manifest.global.group_id:$manifest.go_core.android.artifact_id:$rootProject.ext.version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'commons-io:commons-io:2.6'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

apply from: 'publish.gradle'
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 33af183

Please sign in to comment.