RewriteDERPMapDefaultRelay rewrites the DERP map to use the given access URL as the "embedded relay" access URL. The passed derp map is modified in place. This is used by clients and agents to rewrite the default DERP relay to use their preferred access URL. Both of these clients can use a differen
(ctx context.Context, logger slog.Logger, derpMap *tailcfg.DERPMap, accessURL *url.URL)
| 89 | // |
| 90 | // Note: passed context is only used for logging. |
| 91 | func RewriteDERPMapDefaultRelay(ctx context.Context, logger slog.Logger, derpMap *tailcfg.DERPMap, accessURL *url.URL) { |
| 92 | if derpMap == nil { |
| 93 | return |
| 94 | } |
| 95 | |
| 96 | accessPort := 80 |
| 97 | if accessURL.Scheme == "https" { |
| 98 | accessPort = 443 |
| 99 | } |
| 100 | if accessURL.Port() != "" { |
| 101 | parsedAccessPort, err := strconv.Atoi(accessURL.Port()) |
| 102 | if err != nil { |
| 103 | // This should never happen because URL.Port() returns the empty string |
| 104 | // if the port is not valid. |
| 105 | logger.Critical(ctx, "failed to parse URL port, using default port", |
| 106 | slog.F("port", accessURL.Port()), |
| 107 | slog.F("access_url", accessURL)) |
| 108 | } else { |
| 109 | accessPort = parsedAccessPort |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | for _, region := range derpMap.Regions { |
| 114 | if !region.EmbeddedRelay { |
| 115 | continue |
| 116 | } |
| 117 | |
| 118 | for _, node := range region.Nodes { |
| 119 | if node.STUNOnly { |
| 120 | continue |
| 121 | } |
| 122 | node.HostName = accessURL.Hostname() |
| 123 | node.DERPPort = accessPort |
| 124 | node.ForceHTTP = accessURL.Scheme == "http" |
| 125 | } |
| 126 | } |
| 127 | } |
no outgoing calls
no test coverage detected