Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enabling pubsub and ipns-pubsub via config flags #8510

Merged
merged 11 commits into from
Nov 30, 2021
22 changes: 15 additions & 7 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,26 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
defer repo.Close()

offline, _ := req.Options[offlineKwd].(bool)
ipnsps, _ := req.Options[enableIPNSPubSubKwd].(bool)
pubsub, _ := req.Options[enablePubSubKwd].(bool)
ipnsps, ipnsPsSet := req.Options[enableIPNSPubSubKwd].(bool)
pubsub, psSet := req.Options[enablePubSubKwd].(bool)

if _, hasMplex := req.Options[enableMultiplexKwd]; hasMplex {
log.Errorf("The mplex multiplexer has been enabled by default and the experimental %s flag has been removed.")
log.Errorf("To disable this multiplexer, please configure `Swarm.Transports.Multiplexers'.")
}

cfg, err := repo.Config()
if err != nil {
return err
}

if !psSet {
pubsub = cfg.Pubsub.Enabled.WithDefault(false)
}
if !ipnsPsSet {
ipnsps = cfg.Ipns.UsePubsub.WithDefault(false)
}
aschmahmann marked this conversation as resolved.
Show resolved Hide resolved

// Start assembling node config
ncfg := &core.BuildCfg{
Repo: repo,
Expand All @@ -387,11 +400,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment

routingOption, _ := req.Options[routingOptionKwd].(string)
if routingOption == routingOptionDefaultKwd {
cfg, err := repo.Config()
if err != nil {
return err
}

routingOption = cfg.Routing.Type
if routingOption == "" {
routingOption = routingOptionDHTKwd
Expand Down
27 changes: 26 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ config file at runtime.
- [`Ipns.RepublishPeriod`](#ipnsrepublishperiod)
- [`Ipns.RecordLifetime`](#ipnsrecordlifetime)
- [`Ipns.ResolveCacheSize`](#ipnsresolvecachesize)
- [`Ipns.UsePubsub`](#ipnsusepubsub)
- [`Migration`](#migration)
- [`Migration.DownloadSources`](#migrationdownloadsources)
- [`Migration.Keep`](#migrationkeep)
Expand All @@ -86,6 +87,7 @@ config file at runtime.
- [`Pinning.RemoteServices: Policies.MFS.PinName`](#pinningremoteservices-policiesmfspinname)
- [`Pinning.RemoteServices: Policies.MFS.RepinInterval`](#pinningremoteservices-policiesmfsrepininterval)
- [`Pubsub`](#pubsub)
- [`Pubsub.Enabled`](#pubsubenabled)
- [`Pubsub.Router`](#pubsubrouter)
- [`Pubsub.DisableSigning`](#pubsubdisablesigning)
- [`Peering`](#peering)
Expand Down Expand Up @@ -934,6 +936,17 @@ Default: `128`

Type: `integer` (non-negative, 0 means the default)

### `Ipns.UsePubsub`

**EXPERIMENTAL:** see [experimental-features.md#ipns-pubsub](./experimental-features.md#ipns-pubsub)

Enables IPFS over pubsub experiment for publishing IPNS records in real time.
Read about current limitations at [experimental-features.md#ipfs-pubsub](https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-pubsub).

Default: `disabled`

Type: `flag`

## `Migration`

Migration configures how migrations are downloaded and if the downloads are added to IPFS locally.
Expand Down Expand Up @@ -1066,7 +1079,19 @@ Type: `duration`
## `Pubsub`

Pubsub configures the `ipfs pubsub` subsystem. To use, it must be enabled by
passing the `--enable-pubsub-experiment` flag to the daemon.
passing the `--enable-pubsub-experiment` flag to the daemon
or via the `Pubsub.Enabled` flag below.

### `Pubsub.Enabled`

**EXPERIMENTAL:** see [experimental-features.md#pubsub](./experimental-features.md#pubsub)

Enables the pubsub experiment.
Read about current limitations at [experimental-features.md#ipfs-pubsub](https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md#ipfs-pubsub).

Default: `false`

Type: `flag`

### `Pubsub.Router`

Expand Down
25 changes: 20 additions & 5 deletions docs/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ Candidate, disabled by default but will be enabled by default in 0.6.0.

### In Version

0.4.5
0.4.5 (`--enable-pubsub-experiment`)
0.11.0 (`Pubsub.Enabled` flag in config)

### How to enable

run your daemon with the `--enable-pubsub-experiment` flag. Then use the
`ipfs pubsub` commands.
Run your daemon with the `--enable-pubsub-experiment` flag
or modify your ipfs config and restart the daemon:
```
ipfs config --json Pubsub.Enabled true
```

Then use the `ipfs pubsub` commands.

Configuration documentation can be found in [./config.md]()
Configuration documentation can be found in [go-ipfs/docs/config.md](https://github.com/ipfs/go-ipfs/blob/master/docs/config.md#pubsub)

### Road to being a real feature

Expand Down Expand Up @@ -432,6 +438,9 @@ go-ipfs now automatically shards when directory block is bigger than 256KB, ensu
- This leads to 0.5 IPNS pubsub peers and 0.4 IPNS pubsub peers not being able to find each other in the DHT
- Robustness improvements

0.11.0 :
- Can be enabled via `Ipns.UsePubsub` flag in config

### State

Experimental, default-disabled.
Expand All @@ -452,7 +461,13 @@ Users interested in this feature should upgrade to at least 0.5.0

### How to enable

run your daemon with the `--enable-namesys-pubsub` flag; enables pubsub.
Run your daemon with the `--enable-namesys-pubsub` flag
or modify your ipfs config and restart the daemon:
```
ipfs config --json Ipns.UsePubsub true
```

Note: This feature implicitly enables [ipfs pubsub](#ipfs-pubsub).

### Road to being a real feature

Expand Down
157 changes: 87 additions & 70 deletions test/sharness/t0183-namesys-pubsub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,96 @@ test_expect_success 'init iptb' '
iptb testbed create -type localipfs -count $NUM_NODES -init
'

startup_cluster $NUM_NODES --enable-namesys-pubsub

test_expect_success 'peer ids' '
PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) &&
PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1)
'

test_expect_success 'check namesys pubsub state' '
echo enabled > expected &&
ipfsi 0 name pubsub state > state0 &&
ipfsi 1 name pubsub state > state1 &&
ipfsi 2 name pubsub state > state2 &&
test_cmp expected state0 &&
test_cmp expected state1 &&
test_cmp expected state2
'

# These commands are *expected* to fail. We haven't published anything yet.
test_expect_success 'subscribe nodes to the publisher topic' '
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
true
'

test_expect_success 'check subscriptions' '
echo /ipns/$PEERID_0_BASE36 > expected_base36 &&
echo /ipns/$PEERID_0_B58MH > expected_b58mh &&
ipfsi 1 name pubsub subs > subs1 &&
ipfsi 2 name pubsub subs > subs2 &&
ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh &&
ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh &&
test_cmp expected_base36 subs1 &&
test_cmp expected_base36 subs2 &&
test_cmp expected_b58mh subs1_b58mh &&
test_cmp expected_b58mh subs2_b58mh
'

test_expect_success 'add an object on publisher node' '
echo "ipns is super fun" > file &&
HASH_FILE=$(ipfsi 0 add -q file)
run_ipnspubsub_tests() {

test_expect_success 'peer ids' '
PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) &&
PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1)
'

test_expect_success 'check namesys pubsub state' '
echo enabled > expected &&
ipfsi 0 name pubsub state > state0 &&
ipfsi 1 name pubsub state > state1 &&
ipfsi 2 name pubsub state > state2 &&
test_cmp expected state0 &&
test_cmp expected state1 &&
test_cmp expected state2
'

# These commands are *expected* to fail. We haven't published anything yet.
test_expect_success 'subscribe nodes to the publisher topic' '
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
true
'

test_expect_success 'check subscriptions' '
echo /ipns/$PEERID_0_BASE36 > expected_base36 &&
echo /ipns/$PEERID_0_B58MH > expected_b58mh &&
ipfsi 1 name pubsub subs > subs1 &&
ipfsi 2 name pubsub subs > subs2 &&
ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh &&
ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh &&
test_cmp expected_base36 subs1 &&
test_cmp expected_base36 subs2 &&
test_cmp expected_b58mh subs1_b58mh &&
test_cmp expected_b58mh subs2_b58mh
'

test_expect_success 'add an object on publisher node' '
echo "ipns is super fun" > file &&
HASH_FILE=$(ipfsi 0 add -q file)
'

test_expect_success 'publish that object as an ipns entry' '
ipfsi 0 name publish $HASH_FILE
'

test_expect_success 'wait for the flood' '
sleep 1
'

test_expect_success 'resolve name in subscriber nodes' '
echo "/ipfs/$HASH_FILE" > expected &&
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 > name1 &&
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > name2 &&
test_cmp expected name1 &&
test_cmp expected name2
'

test_expect_success 'cancel subscriptions to the publisher topic' '
ipfsi 1 name pubsub cancel /ipns/$PEERID_0_BASE36 &&
ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36
'

test_expect_success 'check subscriptions' '
rm -f expected && touch expected &&
ipfsi 1 name pubsub subs > subs1 &&
ipfsi 2 name pubsub subs > subs2 &&
test_cmp expected subs1 &&
test_cmp expected subs2
'

test_expect_success "shut down iptb" '
iptb stop
'

}

# Test everything with ipns-pubsub enabled via config
test_expect_success 'enable ipns over pubsub' '
iptb run -- ipfs config --json Ipns.UsePubsub true
'

test_expect_success 'publish that object as an ipns entry' '
ipfsi 0 name publish $HASH_FILE
'

test_expect_success 'wait for the flood' '
sleep 1
'

test_expect_success 'resolve name in subscriber nodes' '
echo "/ipfs/$HASH_FILE" > expected &&
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 > name1 &&
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > name2 &&
test_cmp expected name1 &&
test_cmp expected name2
'
startup_cluster $NUM_NODES
run_ipnspubsub_tests

test_expect_success 'cancel subscriptions to the publisher topic' '
ipfsi 1 name pubsub cancel /ipns/$PEERID_0_BASE36 &&
ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36
'

test_expect_success 'check subscriptions' '
rm -f expected && touch expected &&
ipfsi 1 name pubsub subs > subs1 &&
ipfsi 2 name pubsub subs > subs2 &&
test_cmp expected subs1 &&
test_cmp expected subs2
'

test_expect_success "shut down iptb" '
iptb stop
# Test again, this time CLI parameter override the config
test_expect_success 'enable ipns over pubsub' '
iptb run -- ipfs config --json Ipns.UsePubsub false
'
startup_cluster $NUM_NODES --enable-namesys-pubsub
run_ipnspubsub_tests

test_done
20 changes: 18 additions & 2 deletions test/sharness/t0320-pubsub.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

test_description="Test dht command"
test_description="Test pubsub command"

. lib/test-lib.sh

Expand Down Expand Up @@ -96,7 +96,23 @@ run_pubsub_tests() {

}

# Normal tests
# Normal tests - enabled via config

test_expect_success 'enable the pubsub' '
iptb run -- ipfs config --json Pubsub.Enabled true
'

startup_cluster $NUM_NODES
run_pubsub_tests
test_expect_success 'stop iptb' '
iptb stop
'

test_expect_success 'disable the pubsub' '
iptb run -- ipfs config --json Pubsub.Enabled false
'

# Normal tests - enabled via daemon option flag

startup_cluster $NUM_NODES --enable-pubsub-experiment
run_pubsub_tests
Expand Down