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>
jwh committed
Nov 30, 2021 at 20:00 UTC
029d82c4ea9d73f485b30e5f5100c86502308375
5 files changed
+206
-80
cmd/ipfs/daemon.go
+17
-9
@@ -178,8 +178,8 @@ Headers.
178
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
179
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed").WithDefault(true),
180
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."),
183
cmds.BoolOption(enableMultiplexKwd, "DEPRECATED"),
184
cmds.StringOption(agentVersionSuffix, "Optional suffix to the AgentVersion presented by `ipfs id` and also advertised through BitSwap."),
185
@@ -365,13 +365,26 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
365
defer repo.Close()
366
367
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
+
371
if _, hasMplex := req.Options[enableMultiplexKwd]; hasMplex {
372
log.Errorf("The mplex multiplexer has been enabled by default and the experimental %s flag has been removed.")
373
log.Errorf("To disable this multiplexer, please configure `Swarm.Transports.Multiplexers'.")
374
}
375
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
+
388
// Start assembling node config
389
ncfg := &core.BuildCfg{
390
Repo: repo,
@@ -387,11 +400,6 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
400
401
routingOption, _ := req.Options[routingOptionKwd].(string)
402
if routingOption == routingOptionDefaultKwd {
390
- cfg, err := repo.Config()
391
- if err != nil {
392
- return err
393
- }
394
-
403
routingOption = cfg.Routing.Type
404
if routingOption == "" {
405
routingOption = routingOptionDHTKwd
docs/config.md
+24
-1
@@ -69,6 +69,7 @@ config file at runtime.
69
- [`Ipns.RepublishPeriod`](#ipnsrepublishperiod)
70
- [`Ipns.RecordLifetime`](#ipnsrecordlifetime)
71
- [`Ipns.ResolveCacheSize`](#ipnsresolvecachesize)
72
+ - [`Ipns.UsePubsub`](#ipnsusepubsub)
73
- [`Migration`](#migration)
74
- [`Migration.DownloadSources`](#migrationdownloadsources)
75
- [`Migration.Keep`](#migrationkeep)
@@ -87,6 +88,7 @@ config file at runtime.
88
- [`Pinning.RemoteServices: Policies.MFS.PinName`](#pinningremoteservices-policiesmfspinname)
89
- [`Pinning.RemoteServices: Policies.MFS.RepinInterval`](#pinningremoteservices-policiesmfsrepininterval)
90
- [`Pubsub`](#pubsub)
91
+ - [`Pubsub.Enabled`](#pubsubenabled)
92
- [`Pubsub.Router`](#pubsubrouter)
93
- [`Pubsub.DisableSigning`](#pubsubdisablesigning)
94
- [`Peering`](#peering)
@@ -946,6 +948,16 @@ Default: `128`
948
949
Type: `integer` (non-negative, 0 means the default)
950
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
+
961
## `Migration`
962
963
Migration configures how migrations are downloaded and if the downloads are added to IPFS locally.
@@ -1078,7 +1090,18 @@ Type: `duration`
1090
## `Pubsub`
1091
1092
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`
1105
1106
### `Pubsub.Router`
1107
docs/experimental-features.md
+25
-6
@@ -38,14 +38,22 @@ Candidate, disabled by default but will be enabled by default in 0.6.0.
38
39
### In Version
40
41
-0.4.5
41
+0.4.5 (`--enable-pubsub-experiment`)
42
+0.11.0 (`Pubsub.Enabled` flag in config)
43
44
### How to enable
45
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.
55
48
-Configuration documentation can be found in [./config.md]()
56
+Configuration documentation can be found in [go-ipfs/docs/config.md](./config.md#pubsub)
57
58
### Road to being a real feature
59
@@ -426,12 +434,15 @@ go-ipfs now automatically shards when directory block is bigger than 256KB, ensu
434
0.4.14 :
435
- Introduced
436
429
-0.5.0 :
437
+0.5.0 :
438
- No longer needs to use the DHT for the first resolution
439
- When discovering PubSub peers via the DHT, the DHT key is different from previous versions
440
- This leads to 0.5 IPNS pubsub peers and 0.4 IPNS pubsub peers not being able to find each other in the DHT
441
- Robustness improvements
442
443
+0.11.0 :
444
+ - Can be enabled via `Ipns.UsePubsub` flag in config
445
+
446
### State
447
448
Experimental, default-disabled.
@@ -452,7 +463,15 @@ Users interested in this feature should upgrade to at least 0.5.0
463
464
### How to enable
465
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.
475
476
### Road to being a real feature
477
test/sharness/t0183-namesys-pubsub.sh
+99
-62
@@ -10,79 +10,116 @@ test_expect_success 'init iptb' '
10
iptb testbed create -type localipfs -count $NUM_NODES -init
11
'
12
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
93
'
94
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
97
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
101
'
102
+startup_cluster $NUM_NODES --enable-namesys-pubsub
103
+run_ipnspubsub_tests
104
59
-test_expect_success 'wait for the flood' '
60
- sleep 1
61
-'
105
+# Confirm negative CLI flag takes precedence over positive config
106
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
109
'
110
+startup_cluster $NUM_NODES --enable-namesys-pubsub=false
111
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
114
'
115
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
+"
120
84
-test_expect_success "shut down iptb" '
85
- iptb stop
121
+test_expect_success 'stop iptb' '
122
+ iptb stop
123
'
124
125
test_done
test/sharness/t0320-pubsub.sh
+41
-2
@@ -1,6 +1,6 @@
1
#!/usr/bin/env bash
2
3
-test_description="Test dht command"
3
+test_description="Test pubsub command"
4
5
. lib/test-lib.sh
6
@@ -96,7 +96,23 @@ run_pubsub_tests() {
96
97
}
98
99
-# Normal tests
99
+# Normal tests - enabled via config
100
+
101
+test_expect_success 'enable the pubsub' '
102
+ iptb run -- ipfs config --json Pubsub.Enabled true
103
+'
104
+
105
+startup_cluster $NUM_NODES
106
+run_pubsub_tests
107
+test_expect_success 'stop iptb' '
108
+ iptb stop
109
+'
110
+
111
+test_expect_success 'disable the pubsub' '
112
+ iptb run -- ipfs config --json Pubsub.Enabled false
113
+'
114
+
115
+# Normal tests - enabled via daemon option flag
116
117
startup_cluster $NUM_NODES --enable-pubsub-experiment
118
run_pubsub_tests
@@ -127,4 +143,27 @@ test_expect_success 'node 4 got no unsigned messages' '
143
test_must_be_empty node4_actual
144
'
145
146
+
147
+# Confirm negative CLI flag takes precedence over positive config
148
+
149
+# --enable-pubsub-experiment=false + Pubsub.Enabled:true
150
+
151
+test_expect_success 'enable the pubsub via config' '
152
+ iptb run -- ipfs config --json Pubsub.Enabled true
153
+'
154
+startup_cluster $NUM_NODES --enable-pubsub-experiment=false
155
+
156
+test_expect_success 'pubsub cmd fails because it was disabled via cli flag' '
157
+ test_expect_code 1 ipfsi 4 pubsub ls 2> pubsub_cmd_out
158
+'
159
+
160
+test_expect_success "pubsub cmd produces error" '
161
+ echo "Error: experimental pubsub feature not enabled. Run daemon with --enable-pubsub-experiment to use." > expected &&
162
+ test_cmp expected pubsub_cmd_out
163
+'
164
+
165
+test_expect_success 'stop iptb' '
166
+ iptb stop
167
+'
168
+
169
test_done