mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 10:57:42 +08:00
This logic collects a list of known relays by testing every new connection. It exists so we can dial /p2p-circuit/p2p/QmFoobar addresses (circuit addresses that don't specify the relay). However, this kind of address is useless outside of basic demos as a random relay is practically guaranteed to not be connected to the target peer. Picking a random relay to connect to some peer is almost _never_ the desired behavior.
25 lines
627 B
Go
25 lines
627 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{}
|
|
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()))
|