Commit 7b324b14 authored by vyzo's avatar vyzo
Browse files

remove BasicRouting interface; use PeerRouting and upcast for discovery

parent c2d846a7
...@@ -35,12 +35,7 @@ type AddrsFactory = bhost.AddrsFactory ...@@ -35,12 +35,7 @@ type AddrsFactory = bhost.AddrsFactory
// NATManagerC is a NATManager constructor. // NATManagerC is a NATManager constructor.
type NATManagerC func(inet.Network) bhost.NATManager type NATManagerC func(inet.Network) bhost.NATManager
type BasicRouting interface { type RoutingC func(host.Host) (routing.PeerRouting, error)
routing.ContentRouting
routing.PeerRouting
}
type RoutingC func(host.Host) (BasicRouting, error)
// Config describes a set of settings for a libp2p node // Config describes a set of settings for a libp2p node
// //
...@@ -178,21 +173,24 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) { ...@@ -178,21 +173,24 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
return nil, err return nil, err
} }
if cfg.Relay { crouter, ok := router.(routing.ContentRouting)
discovery := discovery.NewRoutingDiscovery(router) if ok {
if cfg.Relay {
hop := false discovery := discovery.NewRoutingDiscovery(crouter)
for _, opt := range cfg.RelayOpts {
if opt == circuit.OptHop { hop := false
hop = true for _, opt := range cfg.RelayOpts {
break if opt == circuit.OptHop {
hop = true
break
}
} }
}
if hop { if hop {
h = relay.NewRelayHost(swrm.Context(), h.(*bhost.BasicHost), discovery) h = relay.NewRelayHost(swrm.Context(), h.(*bhost.BasicHost), discovery)
} else { } else {
h = relay.NewAutoRelayHost(swrm.Context(), h.(*bhost.BasicHost), discovery) h = relay.NewAutoRelayHost(swrm.Context(), h.(*bhost.BasicHost), discovery)
}
} }
} }
......
...@@ -15,9 +15,6 @@ type Config = config.Config ...@@ -15,9 +15,6 @@ type Config = config.Config
// (`libp2p.New`). // (`libp2p.New`).
type Option = config.Option type Option = config.Option
// BasicRouting is the combination of PeerRouting and ContentRouting
type BasicRouting = config.BasicRouting
// ChainOptions chains multiple options into a single option. // ChainOptions chains multiple options into a single option.
func ChainOptions(opts ...Option) Option { func ChainOptions(opts ...Option) Option {
return func(cfg *Config) error { return func(cfg *Config) error {
......
...@@ -136,7 +136,7 @@ func TestAutoRelay(t *testing.T) { ...@@ -136,7 +136,7 @@ func TestAutoRelay(t *testing.T) {
defer cancel() defer cancel()
mtab := newMockRoutingTable() mtab := newMockRoutingTable()
makeRouting := func(h host.Host) (libp2p.BasicRouting, error) { makeRouting := func(h host.Host) (routing.PeerRouting, error) {
mr := newMockRouting(h, mtab) mr := newMockRouting(h, mtab)
return mr, nil return mr, nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment