5
5
"errors"
6
6
"fmt"
7
7
"net"
8
+ "strings"
8
9
"sync"
9
10
"sync/atomic"
10
11
"time"
@@ -73,13 +74,12 @@ func newUpstreamResolverBase(ctx context.Context, statusRecorder *peer.Status) *
73
74
func (u * upstreamResolverBase ) watchPeersConnStatusChanges () {
74
75
var probeRunning atomic.Bool
75
76
var cancelBackOff context.CancelFunc
76
-
77
77
exponentialBackOff := & backoff.ExponentialBackOff {
78
78
InitialInterval : 200 * time .Millisecond ,
79
79
RandomizationFactor : 0.5 ,
80
80
Multiplier : 1.1 ,
81
- MaxInterval : 5 * time .Second ,
82
- MaxElapsedTime : 15 * time .Second ,
81
+ MaxInterval : 1 * time .Second ,
82
+ MaxElapsedTime : 10 * time .Second ,
83
83
Stop : backoff .Stop ,
84
84
Clock : backoff .SystemClock ,
85
85
}
@@ -98,16 +98,19 @@ func (u *upstreamResolverBase) watchPeersConnStatusChanges() {
98
98
}
99
99
100
100
continualProbe := func () {
101
- // probe continually for 30s when peer count >= 1
102
- if u .statusRecorder .GetConnectedPeersCount () == 0 {
103
- log . Debug ( "O peers connected, running one more DNS probe" )
101
+ // probe continually for 10s when peer count >= 1
102
+ connectedPeersCount := u .statusRecorder .GetConnectedPeersCount ()
103
+ if connectedPeersCount == 0 {
104
104
// cancel backoff operation
105
105
if cancelBackOff != nil {
106
106
cancelBackOff ()
107
107
cancelBackOff = nil
108
108
}
109
- u .probeAvailability ()
110
- return
109
+ if u .areNameServersAllPrivate (u .upstreamServers ) {
110
+ log .Infof ("O peers connected, disabling upstream servers %#v" , u .upstreamServers )
111
+ u .disable (fmt .Errorf ("0 peers connected" ))
112
+ return
113
+ }
111
114
}
112
115
113
116
if probeRunning .Load () {
@@ -152,6 +155,18 @@ func (u *upstreamResolverBase) watchPeersConnStatusChanges() {
152
155
}
153
156
}
154
157
158
+ func (u * upstreamResolverBase ) areNameServersAllPrivate (nameServers []string ) bool {
159
+ u .mutex .Lock ()
160
+ defer u .mutex .Unlock ()
161
+ for _ , n := range nameServers {
162
+ ip := net .ParseIP (strings .Split (n , ":" )[0 ])
163
+ if ! ip .IsPrivate () {
164
+ return false
165
+ }
166
+ }
167
+ return true
168
+ }
169
+
155
170
func (u * upstreamResolverBase ) stop () {
156
171
log .Debugf ("stopping serving DNS for upstreams %s" , u .upstreamServers )
157
172
u .cancel ()
0 commit comments