mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package libp2p
|
|
|
|
import (
|
|
"github.com/libp2p/go-libp2p"
|
|
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
|
libp2pquic "github.com/libp2p/go-libp2p-quic-transport"
|
|
secio "github.com/libp2p/go-libp2p-secio"
|
|
tls "github.com/libp2p/go-libp2p-tls"
|
|
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
func Transports(pnet struct {
|
|
fx.In
|
|
Fprint PNetFingerprint `optional:"true"`
|
|
}) (opts Libp2pOpts) {
|
|
opts.Opts = append(opts.Opts, libp2p.DefaultTransports)
|
|
if pnet.Fprint == nil {
|
|
opts.Opts = append(opts.Opts, libp2p.Transport(libp2pquic.NewTransport))
|
|
}
|
|
return opts
|
|
}
|
|
|
|
func Security(enabled bool) interface{} {
|
|
if !enabled {
|
|
return func() (opts Libp2pOpts) {
|
|
// TODO: shouldn't this be Errorf to guarantee visibility?
|
|
log.Warnf(`Your IPFS node has been configured to run WITHOUT ENCRYPTED CONNECTIONS.
|
|
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) {
|
|
opts.Opts = append(opts.Opts, libp2p.ChainOptions(libp2p.Security(tls.ID, tls.New), libp2p.Security(secio.ID, secio.New)))
|
|
return opts
|
|
}
|
|
}
|
|
|
|
func BandwidthCounter() (opts Libp2pOpts, reporter *metrics.BandwidthCounter) {
|
|
reporter = metrics.NewBandwidthCounter()
|
|
opts.Opts = append(opts.Opts, libp2p.BandwidthReporter(reporter))
|
|
return opts, reporter
|
|
}
|