Skip to content

Commit

Permalink
fixup! chore: avoid logging netcheck send errors if STUN is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
deansheather committed Sep 21, 2023
1 parent 14994e4 commit 1fab4a9
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tailcfg/derpmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type DERPMap struct {
func (m *DERPMap) HasSTUN() bool {
for _, r := range m.Regions {
for _, n := range r.Nodes {
if n.STUNPort > 0 && !n.STUNOnly {
if n.STUNPort >= 0 {
return true
}
}
Expand Down
118 changes: 118 additions & 0 deletions tailcfg/tailcfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,121 @@ func TestCurrentCapabilityVersion(t *testing.T) {
t.Errorf("CurrentCapabilityVersion = %d; want %d", CurrentCapabilityVersion, max)
}
}

func TestDERPMapHasSTUN(t *testing.T) {
cases := []struct {
name string
derpMap *DERPMap
want bool
}{
{
name: "None",
derpMap: &DERPMap{
Regions: map[int]*DERPRegion{
1: {
RegionID: 1,
Nodes: []*DERPNode{
{
RegionID: 1,
Name: "1a",
STUNPort: -1,
},
},
},
2: {
RegionID: 2,
Nodes: []*DERPNode{
{
RegionID: 2,
Name: "2a",
STUNPort: -1,
},
},
},
},
},
want: false,
},
{
name: "One",
derpMap: &DERPMap{
Regions: map[int]*DERPRegion{
1: {
RegionID: 1,
Nodes: []*DERPNode{
{
RegionID: 1,
Name: "1a",
STUNPort: -1,
},
},
},
2: {
RegionID: 2,
Nodes: []*DERPNode{
{
RegionID: 2,
Name: "2a",
STUNPort: -1,
},
{
RegionID: 2,
Name: "2b",
STUNPort: 0, // default
},
},
},
},
},
want: true,
},
{
name: "Some",
derpMap: &DERPMap{
Regions: map[int]*DERPRegion{
1: {
RegionID: 1,
Nodes: []*DERPNode{
{
RegionID: 1,
Name: "1a",
STUNPort: -1,
},
{
RegionID: 1,
Name: "1b",
STUNPort: 1234,
},
},
},
2: {
RegionID: 2,
Nodes: []*DERPNode{
{
RegionID: 2,
Name: "2a",
STUNPort: -1,
},
{
RegionID: 2,
Name: "2b",
STUNPort: 4321,
},
},
},
},
},
want: true,
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
got := c.derpMap.HasSTUN()
if got != c.want {
t.Errorf("got %v; want %v", got, c.want)
}
})
}
}

0 comments on commit 1fab4a9

Please sign in to comment.