@cryptotaxi247 / kubo / commits / d48b80b30

feat: add noise support

We can add a proper configuration option in a followup patch after the RC.

Steven Allen committed May 25, 2020 at 23:01 UTC d48b80b30e72b528e1232e549b2fb3def45be078
7 files changed +109 -13
core/node/groups.go
+1 -1
@@ -120,7 +120,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config) fx.Option {
120 fx.Invoke(libp2p.StartListening(cfg.Addresses.Swarm)),
121 fx.Invoke(libp2p.SetupDiscovery(cfg.Discovery.MDNS.Enabled, cfg.Discovery.MDNS.Interval)),
122
123 - fx.Provide(libp2p.Security(!bcfg.DisableEncryptedConnections)),
123 + fx.Provide(libp2p.Security(!bcfg.DisableEncryptedConnections, cfg.Experimental.OverrideSecurityTransports)),
124
125 fx.Provide(libp2p.Routing),
126 fx.Provide(libp2p.BaseRouting),
core/node/libp2p/transport.go
+28 -2
@@ -1,8 +1,11 @@
1 package libp2p
2
3 import (
4 + "fmt"
5 +
6 "github.com/libp2p/go-libp2p"
7 metrics "github.com/libp2p/go-libp2p-core/metrics"
8 + noise "github.com/libp2p/go-libp2p-noise"
9 libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
10 secio "github.com/libp2p/go-libp2p-secio"
11 tls "github.com/libp2p/go-libp2p-tls"
@@ -10,6 +13,9 @@ import (
13 "go.uber.org/fx"
14 )
15
16 +// default security transports for libp2p
17 +var defaultSecurityTransports = []string{"tls", "secio", "noise"}
18 +
19 func Transports(pnet struct {
20 fx.In
21 Fprint PNetFingerprint `optional:"true"`
@@ -21,7 +27,7 @@ func Transports(pnet struct {
27 return opts
28 }
29
24 -func Security(enabled bool) interface{} {
30 +func Security(enabled bool, securityTransportOverride []string) interface{} {
31 if !enabled {
32 return func() (opts Libp2pOpts) {
33 // TODO: shouldn't this be Errorf to guarantee visibility?
@@ -31,8 +37,28 @@ func Security(enabled bool) interface{} {
37 return opts
38 }
39 }
40 +
41 + securityTransports := defaultSecurityTransports
42 + if len(securityTransportOverride) > 0 {
43 + securityTransports = securityTransportOverride
44 + }
45 +
46 + var libp2pOpts []libp2p.Option
47 + for _, tpt := range securityTransports {
48 + switch tpt {
49 + case "tls":
50 + libp2pOpts = append(libp2pOpts, libp2p.Security(tls.ID, tls.New))
51 + case "secio":
52 + libp2pOpts = append(libp2pOpts, libp2p.Security(secio.ID, secio.New))
53 + case "noise":
54 + libp2pOpts = append(libp2pOpts, libp2p.Security(noise.ID, noise.New))
55 + default:
56 + return fx.Error(fmt.Errorf("invalid security transport specified in config: %s", tpt))
57 + }
58 + }
59 +
60 return func() (opts Libp2pOpts) {
35 - opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2p.Security(tls.ID, tls.New), libp2p.Security(secio.ID, secio.New)))
61 + opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2pOpts...))
62 return opts
63 }
64 }
go.mod
+2 -1
@@ -32,7 +32,7 @@ require (
32 github.com/ipfs/go-ipfs-blockstore v0.1.4
33 github.com/ipfs/go-ipfs-chunker v0.0.5
34 github.com/ipfs/go-ipfs-cmds v0.2.9
35 - github.com/ipfs/go-ipfs-config v0.7.0
35 + github.com/ipfs/go-ipfs-config v0.7.1
36 github.com/ipfs/go-ipfs-ds-help v0.1.1
37 github.com/ipfs/go-ipfs-exchange-interface v0.0.1
38 github.com/ipfs/go-ipfs-exchange-offline v0.0.1
@@ -70,6 +70,7 @@ require (
70 github.com/libp2p/go-libp2p-kbucket v0.4.2
71 github.com/libp2p/go-libp2p-loggables v0.1.0
72 github.com/libp2p/go-libp2p-mplex v0.2.3
73 + github.com/libp2p/go-libp2p-noise v0.1.1
74 github.com/libp2p/go-libp2p-peerstore v0.2.4
75 github.com/libp2p/go-libp2p-pubsub v0.3.0
76 github.com/libp2p/go-libp2p-pubsub-router v0.3.0
go.sum
+7
@@ -115,6 +115,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
115 github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
116 github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
117 github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
118 +github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6 h1:u/UEqS66A5ckRmS4yNpjmVH56sVtS/RfclBAYocb4as=
119 +github.com/flynn/noise v0.0.0-20180327030543-2492fe189ae6/go.mod h1:1i71OnUq3iUe1ma7Lr6yG6/rjvM3emb6yoL7xLFzcVQ=
120 github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk=
121 github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
122 github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
@@ -303,6 +305,8 @@ github.com/ipfs/go-ipfs-cmds v0.2.9 h1:zQTENe9UJrtCb2bOtRoDGjtuo3rQjmuPdPnVlqoBV
305 github.com/ipfs/go-ipfs-cmds v0.2.9/go.mod h1:ZgYiWVnCk43ChwoH8hAmI1IRbuVtq3GSTHwtRB/Kqhk=
306 github.com/ipfs/go-ipfs-config v0.7.0 h1:cClINg8v28//KaYMwt1aSjbS8eGJjNKIEnahpT/2hYk=
307 github.com/ipfs/go-ipfs-config v0.7.0/go.mod h1:GQUxqb0NfkZmEU92PxqqqLVVFTLpoGGUlBaTyDaAqrE=
308 +github.com/ipfs/go-ipfs-config v0.7.1 h1:57ZzoiUIbOIT01x1RconKtCv1MElV/6+kqW8hZY9NJ4=
309 +github.com/ipfs/go-ipfs-config v0.7.1/go.mod h1:GQUxqb0NfkZmEU92PxqqqLVVFTLpoGGUlBaTyDaAqrE=
310 github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
311 github.com/ipfs/go-ipfs-delay v0.0.1 h1:r/UXYyRcddO6thwOnhiznIAiSvxMECGgtv35Xs1IeRQ=
312 github.com/ipfs/go-ipfs-delay v0.0.1/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw=
@@ -501,6 +505,7 @@ github.com/libp2p/go-libp2p v0.7.0 h1:qWmciout2lJclKfRlxqdepsQB7JihcbRhgcRcssP4r
505 github.com/libp2p/go-libp2p v0.7.0/go.mod h1:hZJf8txWeCduQRDC/WSqBGMxaTHCOYHt2xSU1ivxn0k=
506 github.com/libp2p/go-libp2p v0.7.4 h1:xVj1oSlN0C+FlxqiLuHC8WruMvq24xxfeVxmNhTG0r0=
507 github.com/libp2p/go-libp2p v0.7.4/go.mod h1:oXsBlTLF1q7pxr+9w6lqzS1ILpyHsaBPniVO7zIHGMw=
508 +github.com/libp2p/go-libp2p v0.8.1/go.mod h1:QRNH9pwdbEBpx5DTJYg+qxcVaDMAz3Ee/qDKwXujH5o=
509 github.com/libp2p/go-libp2p v0.8.2 h1:gVuk8nZGjnRagJ/mLpBCSJw7bW1yWJrq3EwOk/AC6FM=
510 github.com/libp2p/go-libp2p v0.8.2/go.mod h1:NQDA/F/qArMHGe0J7sDScaKjW8Jh4y/ozQqBbYJ+BnA=
511 github.com/libp2p/go-libp2p v0.8.3 h1:IFWeNzxkBaNO1N8stN9ayFGdC6RmVuSsKd5bou7qpK0=
@@ -620,6 +625,8 @@ github.com/libp2p/go-libp2p-net v0.0.2/go.mod h1:Yt3zgmlsHOgUWSXmt5V/Jpz9upuJBE8
625 github.com/libp2p/go-libp2p-netutil v0.0.1/go.mod h1:GdusFvujWZI9Vt0X5BKqwWWmZFxecf9Gt03cKxm2f/Q=
626 github.com/libp2p/go-libp2p-netutil v0.1.0 h1:zscYDNVEcGxyUpMd0JReUZTrpMfia8PmLKcKF72EAMQ=
627 github.com/libp2p/go-libp2p-netutil v0.1.0/go.mod h1:3Qv/aDqtMLTUyQeundkKsA+YCThNdbQD54k3TqjpbFU=
628 +github.com/libp2p/go-libp2p-noise v0.1.1 h1:vqYQWvnIcHpIoWJKC7Al4D6Hgj0H012TuXRhPwSMGpQ=
629 +github.com/libp2p/go-libp2p-noise v0.1.1/go.mod h1:QDFLdKX7nluB7DEnlVPbz7xlLHdwHFA9HiohJRr3vwM=
630 github.com/libp2p/go-libp2p-peer v0.0.1/go.mod h1:nXQvOBbwVqoP+T5Y5nCjeH4sP9IX/J0AMzcDUVruVoo=
631 github.com/libp2p/go-libp2p-peer v0.1.1/go.mod h1:jkF12jGB4Gk/IOo+yomm+7oLWxF278F7UnrYUQ1Q8es=
632 github.com/libp2p/go-libp2p-peer v0.2.0 h1:EQ8kMjaCUwt/Y5uLgjT8iY2qg0mGUT0N1zUjer50DsY=
test/sharness/lib/iptb-lib.sh
+2 -2
@@ -36,11 +36,11 @@ startup_cluster() {
36
37 if test -n "$other_args"; then
38 test_expect_success "start up nodes with additional args" "
39 - iptb start -wait -- ${other_args[@]}
39 + iptb start -wait [0-$bound] -- ${other_args[@]}
40 "
41 else
42 test_expect_success "start up nodes" '
43 - iptb start -wait
43 + iptb start -wait [0-$bound]
44 '
45 fi
46
test/sharness/t0125-twonode.sh
+22 -7
@@ -89,23 +89,38 @@ test_expect_success "set up tcp testbed" '
89 iptb testbed create -type localipfs -count 2 -force -init
90 '
91
92 +# Test TCP transport
93 +echo "Testing TCP"
94 +tcp_addr='"[\"/ip4/127.0.0.1/tcp/0\"]"'
95 +test_expect_success "use TCP only" '
96 + ipfsi 0 config --json Addresses.Swarm '${tcp_addr}' &&
97 + ipfsi 1 config --json Addresses.Swarm '${tcp_addr}'
98 +'
99 +run_advanced_test
100 +
101 # test multiplex muxer
102 echo "Running advanced tests with mplex"
103 export LIBP2P_MUX_PREFS="/mplex/6.7.0"
104 run_advanced_test "--enable-mplex-experiment"
105 unset LIBP2P_MUX_PREFS
106
98 -# test default configuration
99 -echo "Running advanced tests with default config"
107 +# test Noise
108 +
109 +echo "Running advanced tests with NOISE"
110 +noise_transports='"[\"noise\"]"'
111 +test_expect_success "use noise only" '
112 + ipfsi 0 config --json Experimental.OverrideSecurityTransports '${noise_transports}' &&
113 + ipfsi 1 config --json Experimental.OverrideSecurityTransports '${noise_transports}'
114 +'
115 +
116 run_advanced_test
117
118 # test QUIC
119 echo "Running advanced tests over QUIC"
104 -addr1='"[\"/ip4/127.0.0.1/udp/0/quic/\"]"'
105 -addr2='"[\"/ip4/127.0.0.1/udp/0/quic/\"]"'
106 -test_expect_success "add QUIC swarm addresses" '
107 - ipfsi 0 config --json Addresses.Swarm '$addr1' &&
108 - ipfsi 1 config --json Addresses.Swarm '$addr2'
120 +addr1='"[\"/ip4/127.0.0.1/udp/0/quic\"]"'
121 +test_expect_success "use QUIC only" '
122 + ipfsi 0 config --json Addresses.Swarm '${quic_addr}' &&
123 + ipfsi 1 config --json Addresses.Swarm '${quic_addr}'
124 '
125
126 run_advanced_test
test/sharness/t0191-noise.sh new
+47
@@ -0,0 +1,47 @@
1 +#!/usr/bin/env bash
2 +
3 +test_description="Test ping over NOISE command"
4 +
5 +. lib/test-lib.sh
6 +
7 +test_init_ipfs
8 +
9 +# start iptb + wait for peering
10 +test_expect_success 'init iptb' '
11 + iptb testbed create -type localipfs -count 3 -init
12 +'
13 +
14 +noise_transports='"[\"noise\"]"'
15 +other_transports='"[\"tls\",\"secio\"]"'
16 +tcp_addr='"[\"/ip4/127.0.0.1/tcp/0\"]"'
17 +test_expect_success "configure security transports" '
18 + ipfsi 0 config --json Experimental.OverrideSecurityTransports '${noise_transports}' &&
19 + ipfsi 1 config --json Experimental.OverrideSecurityTransports '${noise_transports}' &&
20 + ipfsi 2 config --json Experimental.OverrideSecurityTransports '${other_transports}' &&
21 + iptb run -- ipfs config --json Addresses.Swarm '${tcp_addr}'
22 +'
23 +
24 +startup_cluster 2
25 +
26 +test_expect_success 'peer ids' '
27 + PEERID_0=$(iptb attr get 0 id) &&
28 + PEERID_1=$(iptb attr get 1 id)
29 +'
30 +
31 +test_expect_success "test ping other" '
32 + ipfsi 0 ping -n2 -- "$PEERID_1" &&
33 + ipfsi 1 ping -n2 -- "$PEERID_0"
34 +'
35 +
36 +test_expect_success "test tls incompatible" '
37 + iptb start --wait 2 &&
38 + test_must_fail iptb connect 2 0 > connect_error 2>&1 &&
39 + test_should_contain "failed to negotiate security protocol" connect_error ||
40 + test_fsh cat connect_error
41 +'
42 +
43 +test_expect_success 'stop iptb' '
44 + iptb stop
45 +'
46 +
47 +test_done