Skip to content

Commit

Permalink
Merge pull request #810 from libp2p/fix/relays-without-content-routing
Browse files Browse the repository at this point in the history
EnableAutoRelay should work without ContentRouting if there are StaticRelays defined
  • Loading branch information
Stebalien authored Mar 7, 2020
2 parents ebb9cb8 + 78ca1bf commit d6d2081
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,6 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
return nil, fmt.Errorf("cannot enable autorelay; relay is not enabled")
}

if router == nil {
h.Close()
return nil, fmt.Errorf("cannot enable autorelay; no routing for discovery")
}

crouter, ok := router.(routing.ContentRouting)
if !ok {
h.Close()
return nil, fmt.Errorf("cannot enable autorelay; no suitable routing for discovery")
}

discovery := discovery.NewRoutingDiscovery(crouter)

hop := false
for _, opt := range cfg.RelayOpts {
if opt == circuit.OptHop {
Expand All @@ -228,11 +215,28 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
}
}

if hop {
// advertise ourselves
relay.Advertise(ctx, discovery)
if !hop && len(cfg.StaticRelays) > 0 {
_ = relay.NewAutoRelay(swrm.Context(), h, nil, router, cfg.StaticRelays)
} else {
_ = relay.NewAutoRelay(swrm.Context(), h, discovery, router, cfg.StaticRelays)
if router == nil {
h.Close()
return nil, fmt.Errorf("cannot enable autorelay; no routing for discovery")
}

crouter, ok := router.(routing.ContentRouting)
if !ok {
h.Close()
return nil, fmt.Errorf("cannot enable autorelay; no suitable routing for discovery")
}

discovery := discovery.NewRoutingDiscovery(crouter)

if hop {
// advertise ourselves
relay.Advertise(ctx, discovery)
} else {
_ = relay.NewAutoRelay(swrm.Context(), h, discovery, router, cfg.StaticRelays)
}
}
}

Expand Down

0 comments on commit d6d2081

Please sign in to comment.