MCPcopy Index your code
hub / github.com/coder/coder / RewriteDERPMapDefaultRelay

Function RewriteDERPMapDefaultRelay

tailnet/derp.go:91–127  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

89//
90// Note: passed context is only used for logging.
91func 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}

Callers 3

RewriteDERPMapMethod · 0.92
RewriteDERPMapMethod · 0.92
RewriteDERPMapMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected