Skip to content
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

chore: avoid logging netcheck send errors if STUN is disabled #40

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions tailcfg/derpmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ type DERPMap struct {
OmitDefaultRegions bool `json:"omitDefaultRegions,omitempty"`
}

// HasSTUN returns true if there are any STUN servers in the DERPMap.
func (m *DERPMap) HasSTUN() bool {
for _, r := range m.Regions {
for _, n := range r.Nodes {
if n.STUNPort > 0 && !n.STUNOnly {
Copy link
Member

Choose a reason for hiding this comment

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

I think we had this bug before, STUNPort: 0 just means the defaullt port. I'm confused on the !n.STUNOnly too, why would you want to exclude STUN only nodes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to if n.StunPort >= 0

return true
}
}
}
return false
}

// / RegionIDs returns the sorted region IDs.
func (m *DERPMap) RegionIDs() []int {
ret := make([]int, 0, len(m.Regions))
Expand Down
9 changes: 8 additions & 1 deletion wgengine/magicsock/magicsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (c *Conn) updateEndpoints(why string) {
c.muCond.Broadcast()
}()
c.dlogf("[v1] magicsock: starting endpoint update (%s)", why)
if c.noV4Send.Load() && runtime.GOOS != "js" {
if c.noV4Send.Load() && c.derpMapHasSTUNNodes() && runtime.GOOS != "js" {
c.mu.Lock()
closed := c.closed
c.mu.Unlock()
Expand All @@ -553,6 +553,13 @@ func (c *Conn) updateEndpoints(why string) {
}
}

// c.mu must NOT be held.
func (c *Conn) derpMapHasSTUNNodes() bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.derpMap != nil && c.derpMap.HasSTUN()
}

// setEndpoints records the new endpoints, reporting whether they're changed.
// It takes ownership of the slice.
func (c *Conn) setEndpoints(endpoints []tailcfg.Endpoint) (changed bool) {
Expand Down