mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 20:07:45 +08:00
Unfortunately, we don't currently have any way to pick out good relays from bad. That means we keep searching, trying bad relays, searching some more, trying _the same relays_, etc. until we randomly find 3 good stable relays. In practice, this means we just keep searching forever and keep thrashing the DHT. see https://github.com/libp2p/go-libp2p/issues/694
25 lines
645 B
Go
25 lines
645 B
Go
package libp2p
|
|
|
|
import (
|
|
"github.com/libp2p/go-libp2p"
|
|
relay "github.com/libp2p/go-libp2p-circuit"
|
|
)
|
|
|
|
func Relay(disable, enableHop bool) func() (opts Libp2pOpts, err error) {
|
|
return func() (opts Libp2pOpts, err error) {
|
|
if disable {
|
|
// Enabled by default.
|
|
opts.Opts = append(opts.Opts, libp2p.DisableRelay())
|
|
} else {
|
|
relayOpts := []relay.RelayOpt{relay.OptDiscovery}
|
|
if enableHop {
|
|
relayOpts = append(relayOpts, relay.OptHop)
|
|
}
|
|
opts.Opts = append(opts.Opts, libp2p.EnableRelay(relayOpts...))
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
var AutoRelay = simpleOpt(libp2p.ChainOptions(libp2p.EnableAutoRelay(), libp2p.DefaultStaticRelays()))
|