2019-07-02 12:40:25 +00:00
|
|
|
package lp2p
|
2019-07-01 09:09:48 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/libp2p/go-libp2p"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/metrics"
|
2020-08-12 18:15:16 +00:00
|
|
|
noise "github.com/libp2p/go-libp2p-noise"
|
2019-07-01 09:09:48 +00:00
|
|
|
tls "github.com/libp2p/go-libp2p-tls"
|
2022-06-29 15:17:48 +00:00
|
|
|
libp2pquic "github.com/libp2p/go-libp2p/p2p/transport/quic"
|
2019-07-01 09:09:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var DefaultTransports = simpleOpt(libp2p.DefaultTransports)
|
|
|
|
var QUIC = simpleOpt(libp2p.Transport(libp2pquic.NewTransport))
|
|
|
|
|
|
|
|
func Security(enabled, preferTLS bool) interface{} {
|
|
|
|
if !enabled {
|
|
|
|
return func() (opts Libp2pOpts) {
|
|
|
|
// TODO: shouldn't this be Errorf to guarantee visibility?
|
2020-02-07 13:02:55 +00:00
|
|
|
log.Warnf(`Your lotus node has been configured to run WITHOUT ENCRYPTED CONNECTIONS.
|
2019-07-01 09:09:48 +00:00
|
|
|
You will not be able to connect to any nodes configured to use encrypted connections`)
|
|
|
|
opts.Opts = append(opts.Opts, libp2p.NoSecurity)
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return func() (opts Libp2pOpts) {
|
|
|
|
if preferTLS {
|
2020-08-12 18:15:16 +00:00
|
|
|
opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2p.Security(tls.ID, tls.New), libp2p.Security(noise.ID, noise.New)))
|
2019-07-01 09:09:48 +00:00
|
|
|
} else {
|
2020-08-12 18:15:16 +00:00
|
|
|
opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2p.Security(noise.ID, noise.New), libp2p.Security(tls.ID, tls.New)))
|
2019-07-01 09:09:48 +00:00
|
|
|
}
|
|
|
|
return opts
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BandwidthCounter() (opts Libp2pOpts, reporter metrics.Reporter) {
|
|
|
|
reporter = metrics.NewBandwidthCounter()
|
|
|
|
opts.Opts = append(opts.Opts, libp2p.BandwidthReporter(reporter))
|
|
|
|
return opts, reporter
|
|
|
|
}
|