sec.go 1.12 KB
Newer Older
tavit ohanian's avatar
tavit ohanian committed
1
package dms3p2p
2 3

import (
tavit ohanian's avatar
tavit ohanian committed
4 5 6 7 8
	config "gitlab.dms3.io/dms3/go-dms3-config"
	"gitlab.dms3.io/p2p/go-p2p"
	noise "gitlab.dms3.io/p2p/go-p2p-noise"
	secio "gitlab.dms3.io/p2p/go-p2p-secio"
	tls "gitlab.dms3.io/p2p/go-p2p-tls"
9 10 11 12
)

func Security(enabled bool, tptConfig config.Transports) interface{} {
	if !enabled {
tavit ohanian's avatar
tavit ohanian committed
13 14
		return func() (opts P2pOpts) {
			log.Errorf(`Your DMS3 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`)
tavit ohanian's avatar
tavit ohanian committed
16
			opts.Opts = append(opts.Opts, p2p.NoSecurity)
17 18 19 20 21
			return opts
		}
	}

	// Using the new config options.
tavit ohanian's avatar
tavit ohanian committed
22
	return func() (opts P2pOpts) {
23 24 25
		opts.Opts = append(opts.Opts, prioritizeOptions([]priorityOption{{
			priority:        tptConfig.Security.TLS,
			defaultPriority: 100,
tavit ohanian's avatar
tavit ohanian committed
26
			opt:             p2p.Security(tls.ID, tls.New),
27 28
		}, {
			priority:        tptConfig.Security.SECIO,
29
			defaultPriority: config.Disabled,
tavit ohanian's avatar
tavit ohanian committed
30
			opt:             p2p.Security(secio.ID, secio.New),
31 32 33
		}, {
			priority:        tptConfig.Security.Noise,
			defaultPriority: 300,
tavit ohanian's avatar
tavit ohanian committed
34
			opt:             p2p.Security(noise.ID, noise.New),
35 36 37 38
		}}))
		return opts
	}
}