Skip to content

Commit

Permalink
fix: can enable autorelay without content routing as long as there ar…
Browse files Browse the repository at this point in the history
…e static relays configured
  • Loading branch information
aschmahmann committed Feb 28, 2020
1 parent 7ba3222 commit 78ca1bf
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 78ca1bf

Please sign in to comment.