2019-07-02 12:40:25 +00:00
|
|
|
package lp2p
|
2019-07-01 09:09:48 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p"
|
|
|
|
coredisc "github.com/libp2p/go-libp2p-core/discovery"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/routing"
|
2019-07-01 09:09:48 +00:00
|
|
|
discovery "github.com/libp2p/go-libp2p-discovery"
|
|
|
|
)
|
|
|
|
|
2020-05-25 10:39:50 +00:00
|
|
|
func NoRelay() func() (opts Libp2pOpts, err error) {
|
2019-07-01 09:09:48 +00:00
|
|
|
return func() (opts Libp2pOpts, err error) {
|
2020-05-25 10:39:50 +00:00
|
|
|
// always disabled, it's an eclipse attack vector
|
|
|
|
opts.Opts = append(opts.Opts, libp2p.DisableRelay())
|
2019-07-01 09:09:48 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: should be use baseRouting or can we use higher level router here?
|
|
|
|
func Discovery(router BaseIpfsRouting) (coredisc.Discovery, error) {
|
|
|
|
crouter, ok := router.(routing.ContentRouting)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("no suitable routing for discovery")
|
|
|
|
}
|
|
|
|
|
|
|
|
return discovery.NewRoutingDiscovery(crouter), nil
|
|
|
|
}
|