Skip to content

fix: find non stun nodes for websocket fallback #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions derp/derphttp/derphttp_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,26 @@ func (c *Client) connect(ctx context.Context, caller string) (client *derp.Clien
case c.useWebsockets():
var urlStr string
var tlsConfig *tls.Config
// WebSocket connections require a DERP to proxy.
// DERP mappings have no explicit requirements on the ordering
// of DERP vs STUNOnly nodes. So we pick the first non-STUNOnly one.
var node *tailcfg.DERPNode
for _, n := range reg.Nodes {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment would help for why this loop is necessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

if n.STUNOnly {
continue
}
node = n
break
}
if node == nil {
return nil, 0, errors.New("no non-STUN-only nodes in region")
}
if c.url != nil {
urlStr = c.url.String()
tlsConfig = c.tlsConfig(nil)
} else {
urlStr = c.urlString(reg.Nodes[0])
tlsConfig = c.tlsConfig(reg.Nodes[0])
urlStr = c.urlString(node)
tlsConfig = c.tlsConfig(node)
}
c.logf("%s: connecting websocket to %v", caller, urlStr)
conn, err := dialWebsocketFunc(ctx, urlStr, tlsConfig, c.Header)
Expand Down