net/netcheck: add a few more STUN retries for prior DERP home

For #1310, maybe.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
crawshaw/upjson
Brad Fitzpatrick 4 years ago committed by Brad Fitzpatrick
parent 0a84359d2d
commit c6358f2247

@ -362,7 +362,7 @@ func makeProbePlan(dm *tailcfg.DERPMap, ifState *interfaces.State, last *Report)
tries = 2 tries = 2
} else if hadBoth { } else if hadBoth {
// For dual stack machines, make the 3rd & slower nodes alternate // For dual stack machines, make the 3rd & slower nodes alternate
// breetween // beetween.
if ri%2 == 0 { if ri%2 == 0 {
do4, do6 = true, false do4, do6 = true, false
} else { } else {
@ -373,6 +373,12 @@ func makeProbePlan(dm *tailcfg.DERPMap, ifState *interfaces.State, last *Report)
do6 = false do6 = false
} }
if reg.RegionID == last.PreferredDERP {
// But if we already had a DERP home, try extra hard to
// make sure it's there so we don't flip flop around.
tries = 4
}
for try := 0; try < tries; try++ { for try := 0; try < tries; try++ {
if len(reg.Nodes) == 0 { if len(reg.Nodes) == 0 {
// Shouldn't be possible. // Shouldn't be possible.
@ -387,6 +393,9 @@ func makeProbePlan(dm *tailcfg.DERPMap, ifState *interfaces.State, last *Report)
prevLatency = defaultActiveRetransmitTime prevLatency = defaultActiveRetransmitTime
} }
delay := time.Duration(try) * prevLatency delay := time.Duration(try) * prevLatency
if try > 1 {
delay += time.Duration(try) * 50 * time.Millisecond
}
if do4 { if do4 {
p4 = append(p4, probe{delay: delay, node: n.Name, proto: probeIPv4}) p4 = append(p4, probe{delay: delay, node: n.Name, proto: probeIPv4})
} }

@ -410,6 +410,35 @@ func TestMakeProbePlan(t *testing.T) {
"region-5-v6": []probe{p("5a", 6), p("5b", 6, 100*ms), p("5c", 6, 200*ms)}, "region-5-v6": []probe{p("5a", 6), p("5b", 6, 100*ms), p("5c", 6, 200*ms)},
}, },
}, },
{
name: "try_harder_for_preferred_derp",
dm: basicMap,
have6if: true,
last: &Report{
RegionLatency: map[int]time.Duration{
1: 10 * time.Millisecond,
2: 20 * time.Millisecond,
3: 30 * time.Millisecond,
4: 40 * time.Millisecond,
},
RegionV4Latency: map[int]time.Duration{
1: 10 * time.Millisecond,
2: 20 * time.Millisecond,
},
RegionV6Latency: map[int]time.Duration{
3: 30 * time.Millisecond,
4: 40 * time.Millisecond,
},
PreferredDERP: 1,
},
want: probePlan{
"region-1-v4": []probe{p("1a", 4), p("1a", 4, 12*ms), p("1a", 4, 124*ms), p("1a", 4, 186*ms)},
"region-1-v6": []probe{p("1a", 6), p("1a", 6, 12*ms), p("1a", 6, 124*ms), p("1a", 6, 186*ms)},
"region-2-v4": []probe{p("2a", 4), p("2b", 4, 24*ms)},
"region-2-v6": []probe{p("2a", 6), p("2b", 6, 24*ms)},
"region-3-v4": []probe{p("3a", 4)},
},
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

Loading…
Cancel
Save