Skip to content

Commit 029d82c

Browse files
jwhlidelaschmahmann
authored
feat: enabling pubsub and ipns-pubsub via config flags (#8510)
* Allow pubsub and namesys-pubsub to be enabled via config Signed-off-by: Joe Holden <jwh@zorins.us> Co-authored-by: Marcin Rataj <lidel@lidel.org> Co-authored-by: Adin Schmahmann <adin.schmahmann@gmail.com>
1 parent ecd2628 commit 029d82c

File tree

5 files changed

+206
-80
lines changed

5 files changed

+206
-80
lines changed

cmd/ipfs/daemon.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ Headers.
178178
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
179179
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").WithDefault(true),
180180
cmds.BoolOption(migrateKwd, "If true, assume yes at the migrate prompt. If false, assume no."),
181-
cmds.BoolOption(enablePubSubKwd, "Instantiate the ipfs daemon with the experimental pubsub feature enabled."),
182-
cmds.BoolOption(enableIPNSPubSubKwd, "Enable IPNS record distribution through pubsub; enables pubsub."),
181+
cmds.BoolOption(enablePubSubKwd, "Enable experimental pubsub feature. Overrides Pubsub.Enabled config."),
182+
cmds.BoolOption(enableIPNSPubSubKwd, "Enable IPNS over pubsub. Implicitly enables pubsub, overrides Ipns.UsePubsub config."),
183183
cmds.BoolOption(enableMultiplexKwd, "DEPRECATED"),
184184
cmds.StringOption(agentVersionSuffix, "Optional suffix to the AgentVersion presented by `ipfs id` and also advertised through BitSwap."),
185185

@@ -365,13 +365,26 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
365365
defer repo.Close()
366366

367367
offline, _ := req.Options[offlineKwd].(bool)
368-
ipnsps, _ := req.Options[enableIPNSPubSubKwd].(bool)
369-
pubsub, _ := req.Options[enablePubSubKwd].(bool)
368+
ipnsps, ipnsPsSet := req.Options[enableIPNSPubSubKwd].(bool)
369+
pubsub, psSet := req.Options[enablePubSubKwd].(bool)
370+
370371
if _, hasMplex := req.Options[enableMultiplexKwd]; hasMplex {
371372
log.Errorf("The mplex multiplexer has been enabled by default and the experimental %s flag has been removed.")
372373
log.Errorf("To disable this multiplexer, please configure `Swarm.Transports.Multiplexers'.")
373374
}
374375

376+
cfg, err := repo.Config()
377+
if err != nil {
378+
return err
379+
}
380+
381+
if !psSet {
382+
pubsub = cfg.Pubsub.Enabled.WithDefault(false)
383+
}
384+
if !ipnsPsSet {
385+
ipnsps = cfg.Ipns.UsePubsub.WithDefault(false)
386+
}
387+
375388
// Start assembling node config
376389
ncfg := &core.BuildCfg{
377390
Repo: repo,
@@ -387,11 +400,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
387400

388401
routingOption, _ := req.Options[routingOptionKwd].(string)
389402
if routingOption == routingOptionDefaultKwd {
390-
cfg, err := repo.Config()
391-
if err != nil {
392-
return err
393-
}
394-
395403
routingOption = cfg.Routing.Type
396404
if routingOption == "" {
397405
routingOption = routingOptionDHTKwd

docs/config.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ config file at runtime.
6969
- [`Ipns.RepublishPeriod`](#ipnsrepublishperiod)
7070
- [`Ipns.RecordLifetime`](#ipnsrecordlifetime)
7171
- [`Ipns.ResolveCacheSize`](#ipnsresolvecachesize)
72+
- [`Ipns.UsePubsub`](#ipnsusepubsub)
7273
- [`Migration`](#migration)
7374
- [`Migration.DownloadSources`](#migrationdownloadsources)
7475
- [`Migration.Keep`](#migrationkeep)
@@ -87,6 +88,7 @@ config file at runtime.
8788
- [`Pinning.RemoteServices: Policies.MFS.PinName`](#pinningremoteservices-policiesmfspinname)
8889
- [`Pinning.RemoteServices: Policies.MFS.RepinInterval`](#pinningremoteservices-policiesmfsrepininterval)
8990
- [`Pubsub`](#pubsub)
91+
- [`Pubsub.Enabled`](#pubsubenabled)
9092
- [`Pubsub.Router`](#pubsubrouter)
9193
- [`Pubsub.DisableSigning`](#pubsubdisablesigning)
9294
- [`Peering`](#peering)
@@ -946,6 +948,16 @@ Default: `128`
946948

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

951+
### `Ipns.UsePubsub`
952+
953+
Enables IPFS over pubsub experiment for publishing IPNS records in real time.
954+
955+
**EXPERIMENTAL:** read about current limitations at [experimental-features.md#ipns-pubsub](./experimental-features.md#ipns-pubsub).
956+
957+
Default: `disabled`
958+
959+
Type: `flag`
960+
949961
## `Migration`
950962

951963
Migration configures how migrations are downloaded and if the downloads are added to IPFS locally.
@@ -1078,7 +1090,18 @@ Type: `duration`
10781090
## `Pubsub`
10791091

10801092
Pubsub configures the `ipfs pubsub` subsystem. To use, it must be enabled by
1081-
passing the `--enable-pubsub-experiment` flag to the daemon.
1093+
passing the `--enable-pubsub-experiment` flag to the daemon
1094+
or via the `Pubsub.Enabled` flag below.
1095+
1096+
### `Pubsub.Enabled`
1097+
1098+
**EXPERIMENTAL:** read about current limitations at [experimental-features.md#ipfs-pubsub](./experimental-features.md#ipfs-pubsub).
1099+
1100+
Enables the pubsub system.
1101+
1102+
Default: `false`
1103+
1104+
Type: `flag`
10821105

10831106
### `Pubsub.Router`
10841107

docs/experimental-features.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ Candidate, disabled by default but will be enabled by default in 0.6.0.
3838

3939
### In Version
4040

41-
0.4.5
41+
0.4.5 (`--enable-pubsub-experiment`)
42+
0.11.0 (`Pubsub.Enabled` flag in config)
4243

4344
### How to enable
4445

45-
run your daemon with the `--enable-pubsub-experiment` flag. Then use the
46-
`ipfs pubsub` commands.
46+
Run your daemon with the `--enable-pubsub-experiment` flag
47+
or modify your ipfs config and restart the daemon:
48+
```
49+
ipfs config --json Pubsub.Enabled true
50+
```
51+
52+
Then use the `ipfs pubsub` commands.
53+
54+
NOTE: `--enable-pubsub-experiment` CLI flag overrides `Pubsub.Enabled` config.
4755

48-
Configuration documentation can be found in [./config.md]()
56+
Configuration documentation can be found in [go-ipfs/docs/config.md](./config.md#pubsub)
4957

5058
### Road to being a real feature
5159

@@ -426,12 +434,15 @@ go-ipfs now automatically shards when directory block is bigger than 256KB, ensu
426434
0.4.14 :
427435
- Introduced
428436

429-
0.5.0 :
437+
0.5.0 :
430438
- No longer needs to use the DHT for the first resolution
431439
- When discovering PubSub peers via the DHT, the DHT key is different from previous versions
432440
- This leads to 0.5 IPNS pubsub peers and 0.4 IPNS pubsub peers not being able to find each other in the DHT
433441
- Robustness improvements
434442

443+
0.11.0 :
444+
- Can be enabled via `Ipns.UsePubsub` flag in config
445+
435446
### State
436447

437448
Experimental, default-disabled.
@@ -452,7 +463,15 @@ Users interested in this feature should upgrade to at least 0.5.0
452463

453464
### How to enable
454465

455-
run your daemon with the `--enable-namesys-pubsub` flag; enables pubsub.
466+
Run your daemon with the `--enable-namesys-pubsub` flag
467+
or modify your ipfs config and restart the daemon:
468+
```
469+
ipfs config --json Ipns.UsePubsub true
470+
```
471+
472+
NOTE:
473+
- This feature implicitly enables [ipfs pubsub](#ipfs-pubsub).
474+
- Passing `--enable-namesys-pubsub` CLI flag overrides `Ipns.UsePubsub` config.
456475

457476
### Road to being a real feature
458477

test/sharness/t0183-namesys-pubsub.sh

Lines changed: 99 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,116 @@ test_expect_success 'init iptb' '
1010
iptb testbed create -type localipfs -count $NUM_NODES -init
1111
'
1212

13-
startup_cluster $NUM_NODES --enable-namesys-pubsub
14-
15-
test_expect_success 'peer ids' '
16-
PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) &&
17-
PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1)
18-
'
19-
20-
test_expect_success 'check namesys pubsub state' '
21-
echo enabled > expected &&
22-
ipfsi 0 name pubsub state > state0 &&
23-
ipfsi 1 name pubsub state > state1 &&
24-
ipfsi 2 name pubsub state > state2 &&
25-
test_cmp expected state0 &&
26-
test_cmp expected state1 &&
27-
test_cmp expected state2
28-
'
29-
30-
# These commands are *expected* to fail. We haven't published anything yet.
31-
test_expect_success 'subscribe nodes to the publisher topic' '
32-
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
33-
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
34-
true
13+
run_ipnspubsub_tests() {
14+
15+
test_expect_success 'peer ids' '
16+
PEERID_0_BASE36=$(ipfsi 0 key list --ipns-base=base36 -l | grep self | head -n 1 | cut -d " " -f1) &&
17+
PEERID_0_B58MH=$(ipfsi 0 key list --ipns-base=b58mh -l | grep self | head -n 1 | cut -d " " -f1)
18+
'
19+
20+
test_expect_success 'check namesys pubsub state' '
21+
echo enabled > expected &&
22+
ipfsi 0 name pubsub state > state0 &&
23+
ipfsi 1 name pubsub state > state1 &&
24+
ipfsi 2 name pubsub state > state2 &&
25+
test_cmp expected state0 &&
26+
test_cmp expected state1 &&
27+
test_cmp expected state2
28+
'
29+
30+
# These commands are *expected* to fail. We haven't published anything yet.
31+
test_expect_success 'subscribe nodes to the publisher topic' '
32+
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
33+
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 --timeout=1s;
34+
true
35+
'
36+
37+
test_expect_success 'check subscriptions' '
38+
echo /ipns/$PEERID_0_BASE36 > expected_base36 &&
39+
echo /ipns/$PEERID_0_B58MH > expected_b58mh &&
40+
ipfsi 1 name pubsub subs > subs1 &&
41+
ipfsi 2 name pubsub subs > subs2 &&
42+
ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh &&
43+
ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh &&
44+
test_cmp expected_base36 subs1 &&
45+
test_cmp expected_base36 subs2 &&
46+
test_cmp expected_b58mh subs1_b58mh &&
47+
test_cmp expected_b58mh subs2_b58mh
48+
'
49+
50+
test_expect_success 'add an object on publisher node' '
51+
echo "ipns is super fun" > file &&
52+
HASH_FILE=$(ipfsi 0 add -q file)
53+
'
54+
55+
test_expect_success 'publish that object as an ipns entry' '
56+
ipfsi 0 name publish $HASH_FILE
57+
'
58+
59+
test_expect_success 'wait for the flood' '
60+
sleep 1
61+
'
62+
63+
test_expect_success 'resolve name in subscriber nodes' '
64+
echo "/ipfs/$HASH_FILE" > expected &&
65+
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 > name1 &&
66+
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > name2 &&
67+
test_cmp expected name1 &&
68+
test_cmp expected name2
69+
'
70+
71+
test_expect_success 'cancel subscriptions to the publisher topic' '
72+
ipfsi 1 name pubsub cancel /ipns/$PEERID_0_BASE36 &&
73+
ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36
74+
'
75+
76+
test_expect_success 'check subscriptions' '
77+
rm -f expected && touch expected &&
78+
ipfsi 1 name pubsub subs > subs1 &&
79+
ipfsi 2 name pubsub subs > subs2 &&
80+
test_cmp expected subs1 &&
81+
test_cmp expected subs2
82+
'
83+
84+
test_expect_success "shut down iptb" '
85+
iptb stop
86+
'
87+
88+
}
89+
90+
# Test everything with ipns-pubsub enabled via config
91+
test_expect_success 'enable ipns over pubsub' '
92+
iptb run -- ipfs config --json Ipns.UsePubsub true
3593
'
3694

37-
test_expect_success 'check subscriptions' '
38-
echo /ipns/$PEERID_0_BASE36 > expected_base36 &&
39-
echo /ipns/$PEERID_0_B58MH > expected_b58mh &&
40-
ipfsi 1 name pubsub subs > subs1 &&
41-
ipfsi 2 name pubsub subs > subs2 &&
42-
ipfsi 1 name pubsub subs --ipns-base=b58mh > subs1_b58mh &&
43-
ipfsi 2 name pubsub subs --ipns-base=b58mh > subs2_b58mh &&
44-
test_cmp expected_base36 subs1 &&
45-
test_cmp expected_base36 subs2 &&
46-
test_cmp expected_b58mh subs1_b58mh &&
47-
test_cmp expected_b58mh subs2_b58mh
48-
'
49-
50-
test_expect_success 'add an object on publisher node' '
51-
echo "ipns is super fun" > file &&
52-
HASH_FILE=$(ipfsi 0 add -q file)
53-
'
95+
startup_cluster $NUM_NODES
96+
run_ipnspubsub_tests
5497

55-
test_expect_success 'publish that object as an ipns entry' '
56-
ipfsi 0 name publish $HASH_FILE
98+
# Test again, this time CLI parameter override the config
99+
test_expect_success 'enable ipns over pubsub' '
100+
iptb run -- ipfs config --json Ipns.UsePubsub false
57101
'
102+
startup_cluster $NUM_NODES --enable-namesys-pubsub
103+
run_ipnspubsub_tests
58104

59-
test_expect_success 'wait for the flood' '
60-
sleep 1
61-
'
105+
# Confirm negative CLI flag takes precedence over positive config
62106

63-
test_expect_success 'resolve name in subscriber nodes' '
64-
echo "/ipfs/$HASH_FILE" > expected &&
65-
ipfsi 1 name resolve /ipns/$PEERID_0_BASE36 > name1 &&
66-
ipfsi 2 name resolve /ipns/$PEERID_0_BASE36 > name2 &&
67-
test_cmp expected name1 &&
68-
test_cmp expected name2
107+
test_expect_success 'enable the pubsub-ipns via config' '
108+
iptb run -- ipfs config --json Ipns.UsePubsub true
69109
'
110+
startup_cluster $NUM_NODES --enable-namesys-pubsub=false
70111

71-
test_expect_success 'cancel subscriptions to the publisher topic' '
72-
ipfsi 1 name pubsub cancel /ipns/$PEERID_0_BASE36 &&
73-
ipfsi 2 name pubsub cancel /ipns/$PEERID_0_BASE36
112+
test_expect_success 'ipns pubsub cmd fails because it was disabled via cli flag' '
113+
test_expect_code 1 ipfsi 1 name pubsub subs 2> pubsubipns_cmd_out
74114
'
75115

76-
test_expect_success 'check subscriptions' '
77-
rm -f expected && touch expected &&
78-
ipfsi 1 name pubsub subs > subs1 &&
79-
ipfsi 2 name pubsub subs > subs2 &&
80-
test_cmp expected subs1 &&
81-
test_cmp expected subs2
82-
'
116+
test_expect_success "ipns pubsub cmd produces error" "
117+
echo -e \"Error: IPNS pubsub subsystem is not enabled\nUse 'ipfs name pubsub subs --help' for information about this command\" > expected &&
118+
test_cmp expected pubsubipns_cmd_out
119+
"
83120

84-
test_expect_success "shut down iptb" '
85-
iptb stop
121+
test_expect_success 'stop iptb' '
122+
iptb stop
86123
'
87124

88125
test_done

0 commit comments

Comments
 (0)