Skip to content

Commit 1a4d56a

Browse files
committed
fix: github actions
1 parent 5dc9587 commit 1a4d56a

File tree

4 files changed

+83
-20
lines changed

4 files changed

+83
-20
lines changed

internal/derperer/derp_endpoint.go

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,27 @@ type DerpEndpoint struct {
3232
Error string `json:"error,omitempty"`
3333
}
3434

35-
func (d *DerpEndpoint) Convert() *tailcfg.DERPRegion {
36-
return &tailcfg.DERPRegion{
37-
RegionID: d.ID,
38-
RegionCode: d.Name,
39-
RegionName: d.Name,
40-
Nodes: []*tailcfg.DERPNode{
35+
func (d *DerpEndpoint) Convert() *DERPRegion {
36+
return &DERPRegion{
37+
DERPRegion: tailcfg.DERPRegion{
38+
RegionID: d.ID,
39+
RegionCode: d.Name,
40+
RegionName: d.Name,
41+
},
42+
Nodes: []*DERPNode{
4143
{
42-
Name: d.Name,
43-
RegionID: d.ID,
44-
HostName: d.Host,
45-
IPv4: d.IPv4,
46-
IPv6: d.IPv6,
47-
DERPPort: d.Port,
48-
InsecureForTests: d.Insecure,
44+
DERPNode: tailcfg.DERPNode{
45+
Name: d.Name,
46+
RegionID: d.ID,
47+
HostName: d.Host,
48+
IPv4: d.IPv4,
49+
IPv6: d.IPv6,
50+
DERPPort: d.Port,
51+
InsecureForTests: d.Insecure,
52+
},
53+
Latency: d.Latency,
54+
Bandwidth: d.Bandwidth,
55+
Status: d.Status,
4956
},
5057
},
5158
}
@@ -55,15 +62,21 @@ type DerpEndpoints []*DerpEndpoint
5562

5663
func (d DerpEndpoints) Len() int { return len(d) }
5764

58-
func (d DerpEndpoints) Convert() *tailcfg.DERPMap {
65+
func (d DerpEndpoints) Convert() *DERPMap {
5966
if d == nil {
60-
return nil
67+
return &DERPMap{
68+
DERPMap: tailcfg.DERPMap{
69+
Regions: map[int]*tailcfg.DERPRegion{},
70+
},
71+
}
6172
}
62-
m := &tailcfg.DERPMap{
63-
Regions: make(map[int]*tailcfg.DERPRegion),
64-
HomeParams: &tailcfg.DERPHomeParams{
65-
RegionScore: map[int]float64{},
73+
m := &DERPMap{
74+
DERPMap: tailcfg.DERPMap{
75+
HomeParams: &tailcfg.DERPHomeParams{
76+
RegionScore: map[int]float64{},
77+
},
6678
},
79+
Regions: make(map[int]*DERPRegion),
6780
}
6881
for _, endpoint := range d {
6982
m.Regions[endpoint.ID] = endpoint.Convert()

internal/derperer/extend_map.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package derperer
2+
3+
import (
4+
"time"
5+
6+
"github.com/yoshino-s/derperer/pkg/speedtest"
7+
"tailscale.com/tailcfg"
8+
)
9+
10+
type DERPMap struct {
11+
tailcfg.DERPMap
12+
Regions map[int]*DERPRegion
13+
}
14+
15+
type DERPRegion struct {
16+
tailcfg.DERPRegion
17+
Nodes []*DERPNode
18+
}
19+
20+
type DERPNode struct {
21+
tailcfg.DERPNode
22+
Latency time.Duration `json:"latency,omitempty"`
23+
Bandwidth speedtest.Unit `json:"bandwidth,omitempty"`
24+
Status DerpStatus `json:"status,omitempty"`
25+
}
26+
27+
func (n *DERPNode) ToOriginal() *tailcfg.DERPNode {
28+
return &n.DERPNode
29+
}
30+
31+
func (r *DERPRegion) ToOriginal() *tailcfg.DERPRegion {
32+
region := &r.DERPRegion
33+
region.Nodes = make([]*tailcfg.DERPNode, 0, len(r.Nodes))
34+
for _, node := range r.Nodes {
35+
region.Nodes = append(region.Nodes, node.ToOriginal())
36+
}
37+
return region
38+
}
39+
40+
func (m *DERPMap) ToOriginal() *tailcfg.DERPMap {
41+
derpMap := &m.DERPMap
42+
derpMap.Regions = make(map[int]*tailcfg.DERPRegion)
43+
for id, region := range m.Regions {
44+
derpMap.Regions[id] = region.ToOriginal()
45+
}
46+
return derpMap
47+
}

internal/derperer/map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (d *DerpererService) Configuration() configuration.Configuration {
4444
}
4545

4646
func (d *DerpererService) testDerpEndpoint(endpoint *DerpEndpoint) {
47-
res, err := d.SpeedtestService.CheckDerp(endpoint.Convert(), d.config.CheckDuration)
47+
res, err := d.SpeedtestService.CheckDerp(endpoint.Convert().ToOriginal(), d.config.CheckDuration)
4848
if err != nil {
4949
d.Logger.Error("failed to check derp", zap.Any("endpoint", endpoint), zap.Error(err))
5050
endpoint.Error = err.Error()

pkg/speedtest/unit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (b Unit) MarshalText() ([]byte, error) {
5353
func (b Unit) MarshalJSON() ([]byte, error) {
5454
return []byte(fmt.Sprintf(`"%s"`, b.String())), nil
5555
}
56+
func (b Unit) IsZero() bool {
57+
return b.Value == 0
58+
}
5659
func (b *Unit) UnmarshalText(data []byte) error {
5760
u, err := ParseUnit(string(data), b.Uint)
5861
if err != nil {

0 commit comments

Comments
 (0)