mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
constructor: libp2p simpleOpts
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
ed514b9177
commit
3a12454c95
@ -280,6 +280,11 @@ func makeSmuxTransportOption(mplexExp bool) libp2p.Option {
|
||||
return libp2p.ChainOptions(opts...)
|
||||
}
|
||||
|
||||
var NatPortMap = simpleOpt(libp2p.NATPortMap())
|
||||
var AutoRealy = simpleOpt(libp2p.EnableAutoRelay())
|
||||
var DefaultTransports = simpleOpt(libp2p.DefaultTransports)
|
||||
var QUIC = simpleOpt(libp2p.Transport(libp2pquic.NewTransport))
|
||||
|
||||
func SmuxTransport(mplex bool) func() (opts Libp2pOpts, err error) {
|
||||
return func() (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, makeSmuxTransportOption(mplex))
|
||||
@ -287,11 +292,6 @@ func SmuxTransport(mplex bool) func() (opts Libp2pOpts, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func NatPortMap() (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, libp2p.NATPortMap())
|
||||
return
|
||||
}
|
||||
|
||||
func Relay(disable, enableHop bool) func() (opts Libp2pOpts, err error) {
|
||||
return func() (opts Libp2pOpts, err error) {
|
||||
if disable {
|
||||
@ -308,21 +308,6 @@ func Relay(disable, enableHop bool) func() (opts Libp2pOpts, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func AutoRealy() (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, libp2p.EnableAutoRelay())
|
||||
return
|
||||
}
|
||||
|
||||
func DefaultTransports() (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, libp2p.DefaultTransports)
|
||||
return
|
||||
}
|
||||
|
||||
func QUIC() (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, libp2p.Transport(libp2pquic.NewTransport))
|
||||
return
|
||||
}
|
||||
|
||||
func Security(enabled, preferTLS bool) interface{} {
|
||||
if !enabled {
|
||||
return func() (opts Libp2pOpts) {
|
||||
@ -555,3 +540,10 @@ func StartListening(addresses []string) func(host host.Host) error {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func simpleOpt(opt libp2p.Option) func() (opts Libp2pOpts, err error) {
|
||||
return func() (opts Libp2pOpts, err error) {
|
||||
opts.Opts = append(opts.Opts, opt)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user