master
go 34 lines 982 Bytes
Raw
1 package libp2p
2
3 import (
4 "github.com/ipfs/kubo/config"
5
6 "github.com/libp2p/go-libp2p"
7 "github.com/libp2p/go-libp2p/p2p/security/noise"
8 tls "github.com/libp2p/go-libp2p/p2p/security/tls"
9 )
10
11 func Security(enabled bool, tptConfig config.Transports) any {
12 if !enabled {
13 return func() (opts Libp2pOpts) {
14 log.Errorf(`Your IPFS node has been configured to run WITHOUT ENCRYPTED CONNECTIONS.
15 You will not be able to connect to any nodes configured to use encrypted connections`)
16 opts.Opts = append(opts.Opts, libp2p.NoSecurity)
17 return opts
18 }
19 }
20
21 // Using the new config options.
22 return func() (opts Libp2pOpts) {
23 opts.Opts = append(opts.Opts, prioritizeOptions([]priorityOption{{
24 priority: tptConfig.Security.TLS,
25 defaultPriority: 100,
26 opt: libp2p.Security(tls.ID, tls.New),
27 }, {
28 priority: tptConfig.Security.Noise,
29 defaultPriority: 200,
30 opt: libp2p.Security(noise.ID, noise.New),
31 }}))
32 return opts
33 }
34 }