@@ -26,7 +26,8 @@ import (
26
26
)
27
27
28
28
type DERPReport struct {
29
- mu sync.Mutex
29
+ mu sync.Mutex
30
+ Healthy bool `json:"healthy"`
30
31
31
32
Regions map [int ]* DERPRegionReport `json:"regions"`
32
33
@@ -35,17 +36,19 @@ type DERPReport struct {
35
36
}
36
37
37
38
type DERPRegionReport struct {
38
- mu sync.Mutex
39
- Region * tailcfg. DERPRegion `json:"region "`
39
+ mu sync.Mutex
40
+ Healthy bool `json:"healthy "`
40
41
41
- NodeReports []* DERPNodeReport `json:"node_reports"`
42
+ Region * tailcfg.DERPRegion `json:"region"`
43
+ NodeReports []* DERPNodeReport `json:"node_reports"`
42
44
}
43
45
type DERPNodeReport struct {
44
- Node * tailcfg.DERPNode `json:"node"`
45
-
46
46
mu sync.Mutex
47
47
clientCounter int
48
48
49
+ Healthy bool `json:"healthy"`
50
+ Node * tailcfg.DERPNode `json:"node"`
51
+
49
52
CanExchangeMessages bool `json:"can_exchange_messages"`
50
53
RoundTripPing time.Duration `json:"round_trip_ping"`
51
54
UsesWebsocket bool `json:"uses_websocket"`
@@ -66,6 +69,7 @@ type DERPReportOptions struct {
66
69
}
67
70
68
71
func (r * DERPReport ) Run (ctx context.Context , opts * DERPReportOptions ) error {
72
+ r .Healthy = true
69
73
r .Regions = map [int ]* DERPRegionReport {}
70
74
71
75
eg , ctx := errgroup .WithContext (ctx )
@@ -84,6 +88,9 @@ func (r *DERPReport) Run(ctx context.Context, opts *DERPReportOptions) error {
84
88
85
89
r .mu .Lock ()
86
90
r .Regions [region .RegionID ] = & regionReport
91
+ if ! regionReport .Healthy {
92
+ r .Healthy = false
93
+ }
87
94
r .mu .Unlock ()
88
95
return nil
89
96
})
@@ -108,14 +115,16 @@ func (r *DERPReport) Run(ctx context.Context, opts *DERPReportOptions) error {
108
115
}
109
116
110
117
func (r * DERPRegionReport ) Run (ctx context.Context ) error {
118
+ r .Healthy = true
111
119
r .NodeReports = []* DERPNodeReport {}
112
120
eg , ctx := errgroup .WithContext (ctx )
113
121
114
122
for _ , node := range r .Region .Nodes {
115
123
node := node
116
124
eg .Go (func () error {
117
125
nodeReport := DERPNodeReport {
118
- Node : node ,
126
+ Node : node ,
127
+ Healthy : true ,
119
128
}
120
129
121
130
err := nodeReport .Run (ctx )
@@ -125,6 +134,9 @@ func (r *DERPRegionReport) Run(ctx context.Context) error {
125
134
126
135
r .mu .Lock ()
127
136
r .NodeReports = append (r .NodeReports , & nodeReport )
137
+ if ! nodeReport .Healthy {
138
+ r .Healthy = false
139
+ }
128
140
r .mu .Unlock ()
129
141
return nil
130
142
})
@@ -159,6 +171,9 @@ func (r *DERPNodeReport) Run(ctx context.Context) error {
159
171
r .doExchangeMessage (ctx )
160
172
r .doSTUNTest (ctx )
161
173
174
+ if ! r .CanExchangeMessages || r .UsesWebsocket || r .STUN .Error != nil {
175
+ r .Healthy = false
176
+ }
162
177
return nil
163
178
}
164
179
0 commit comments