From 78ca1bf57c421b79ce278075c7a311f7775f72b8 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Fri, 28 Feb 2020 00:40:52 -0500 Subject: [PATCH] fix: can enable autorelay without content routing as long as there are static relays configured --- config/config.go | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index 2ace430a49..65ed52a3ba 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { @@ -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) + } } }