all: apply go fix
Updates #cleanup Signed-off-by: Adriano Sela Aviles <adriano@tailscale.com>
This commit is contained in:
committed by
Adriano Sela Aviles
parent
a5102d3fcb
commit
d69bf2685a
@@ -76,7 +76,7 @@ type ReloadConfigResponse struct {
|
|||||||
type ExitNodeSuggestionResponse struct {
|
type ExitNodeSuggestionResponse struct {
|
||||||
ID tailcfg.StableNodeID
|
ID tailcfg.StableNodeID
|
||||||
Name string
|
Name string
|
||||||
Location tailcfg.LocationView `json:",omitempty"`
|
Location tailcfg.LocationView `json:",omitzero"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DNSOSConfig mimics dns.OSConfig without forcing us to import the entire dns package
|
// DNSOSConfig mimics dns.OSConfig without forcing us to import the entire dns package
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ type Key struct {
|
|||||||
|
|
||||||
// KeyCapabilities are the capabilities of a Key.
|
// KeyCapabilities are the capabilities of a Key.
|
||||||
type KeyCapabilities struct {
|
type KeyCapabilities struct {
|
||||||
Devices KeyDeviceCapabilities `json:"devices,omitempty"`
|
Devices KeyDeviceCapabilities `json:"devices"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// KeyDeviceCapabilities are the device-related capabilities of a Key.
|
// KeyDeviceCapabilities are the device-related capabilities of a Key.
|
||||||
|
|||||||
+1
-1
@@ -167,7 +167,7 @@ type ClientInfo struct {
|
|||||||
// trusted clients. It's required to subscribe to the
|
// trusted clients. It's required to subscribe to the
|
||||||
// connection list & forward packets. It's empty for regular
|
// connection list & forward packets. It's empty for regular
|
||||||
// users.
|
// users.
|
||||||
MeshKey key.DERPMesh `json:"meshKey,omitempty,omitzero"`
|
MeshKey key.DERPMesh `json:"meshKey,omitzero"`
|
||||||
|
|
||||||
// Version is the DERP protocol version that the client was built with.
|
// Version is the DERP protocol version that the client was built with.
|
||||||
// See the ProtocolVersion const.
|
// See the ProtocolVersion const.
|
||||||
|
|||||||
@@ -315,9 +315,7 @@ func (s *userServer) runLoop() {
|
|||||||
consecutiveFailures = 1
|
consecutiveFailures = 1
|
||||||
}
|
}
|
||||||
sleepTime := time.Duration(math.Pow(2, consecutiveFailures)) * time.Millisecond
|
sleepTime := time.Duration(math.Pow(2, consecutiveFailures)) * time.Millisecond
|
||||||
if sleepTime > maxSleepTime {
|
sleepTime = min(sleepTime, maxSleepTime)
|
||||||
sleepTime = maxSleepTime
|
|
||||||
}
|
|
||||||
s.logf("user server % v stopped with error %v, will try again in %v", s.executable, err, sleepTime)
|
s.logf("user server % v stopped with error %v, will try again in %v", s.executable, err, sleepTime)
|
||||||
time.Sleep(sleepTime)
|
time.Sleep(sleepTime)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,7 @@ func (d *DirFile) Readdir(count int) ([]fs.FileInfo, error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
n := len(d.children)
|
n := min(count, len(d.children))
|
||||||
if count < n {
|
|
||||||
n = count
|
|
||||||
}
|
|
||||||
result := d.children[:n]
|
result := d.children[:n]
|
||||||
d.children = d.children[n:]
|
d.children = d.children[n:]
|
||||||
if len(d.children) == 0 {
|
if len(d.children) == 0 {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -181,12 +182,7 @@ func (sl *serialLog) lastN(n int) []string {
|
|||||||
func (sl *serialLog) findLine(pred func(string) bool) bool {
|
func (sl *serialLog) findLine(pred func(string) bool) bool {
|
||||||
sl.mu.Lock()
|
sl.mu.Lock()
|
||||||
defer sl.mu.Unlock()
|
defer sl.mu.Unlock()
|
||||||
for _, line := range sl.lines {
|
return slices.ContainsFunc(sl.lines, pred)
|
||||||
if pred(line) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestBusyboxInTsapp boots the tsapp image in QEMU and verifies that
|
// TestBusyboxInTsapp boots the tsapp image in QEMU and verifies that
|
||||||
|
|||||||
@@ -144,10 +144,7 @@ func (m *memBackend) ReadAt(p []byte, off int64) (int, error) {
|
|||||||
absOff := off + int64(total)
|
absOff := off + int64(total)
|
||||||
page := absOff / memPageSize
|
page := absOff / memPageSize
|
||||||
within := int(absOff % memPageSize)
|
within := int(absOff % memPageSize)
|
||||||
room := memPageSize - within
|
room := min(memPageSize-within, len(p)-total)
|
||||||
if room > len(p)-total {
|
|
||||||
room = len(p) - total
|
|
||||||
}
|
|
||||||
if chunk, ok := m.pages[page]; ok {
|
if chunk, ok := m.pages[page]; ok {
|
||||||
copy(p[total:total+room], chunk[within:within+room])
|
copy(p[total:total+room], chunk[within:within+room])
|
||||||
}
|
}
|
||||||
@@ -183,10 +180,7 @@ func (m *memBackend) WriteAt(p []byte, off int64) (int, error) {
|
|||||||
absOff := off + int64(total)
|
absOff := off + int64(total)
|
||||||
page := absOff / memPageSize
|
page := absOff / memPageSize
|
||||||
within := int(absOff % memPageSize)
|
within := int(absOff % memPageSize)
|
||||||
room := memPageSize - within
|
room := min(memPageSize-within, len(p)-total)
|
||||||
if room > len(p)-total {
|
|
||||||
room = len(p) - total
|
|
||||||
}
|
|
||||||
chunk, ok := m.pages[page]
|
chunk, ok := m.pages[page]
|
||||||
if !ok && isAllZero(p[total:total+room]) {
|
if !ok && isAllZero(p[total:total+room]) {
|
||||||
// Don't allocate a fresh zero page.
|
// Don't allocate a fresh zero page.
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ func init() {
|
|||||||
|
|
||||||
func breakTCPConnsDarwin() error {
|
func breakTCPConnsDarwin() error {
|
||||||
var matched int
|
var matched int
|
||||||
for fd := 0; fd < 1000; fd++ {
|
for fd := range 1000 {
|
||||||
_, err := unix.GetsockoptTCPConnectionInfo(fd, unix.IPPROTO_TCP, unix.TCP_CONNECTION_INFO)
|
_, err := unix.GetsockoptTCPConnectionInfo(fd, unix.IPPROTO_TCP, unix.TCP_CONNECTION_INFO)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
matched++
|
matched++
|
||||||
|
|||||||
@@ -2123,8 +2123,7 @@ func TestWatchNotificationsCallbacks(t *testing.T) {
|
|||||||
|
|
||||||
func TestWatchNotificationsClosesSlowConsumer(t *testing.T) {
|
func TestWatchNotificationsClosesSlowConsumer(t *testing.T) {
|
||||||
b := newTestLocalBackend(t)
|
b := newTestLocalBackend(t)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx := t.Context()
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
watchAdded := make(chan struct{})
|
watchAdded := make(chan struct{})
|
||||||
firstNotify := make(chan struct{}, 1)
|
firstNotify := make(chan struct{}, 1)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func TestTruncateLabelValue(t *testing.T) {
|
|||||||
func TestTruncateLabelValueDeterministic(t *testing.T) {
|
func TestTruncateLabelValueDeterministic(t *testing.T) {
|
||||||
input := strings.Repeat("a", 100)
|
input := strings.Repeat("a", 100)
|
||||||
first := TruncateLabelValue(input)
|
first := TruncateLabelValue(input)
|
||||||
for i := 0; i < 10; i++ {
|
for range 10 {
|
||||||
got := TruncateLabelValue(input)
|
got := TruncateLabelValue(input)
|
||||||
if got != first {
|
if got != first {
|
||||||
t.Fatalf("non-deterministic: got %q, want %q", got, first)
|
t.Fatalf("non-deterministic: got %q, want %q", got, first)
|
||||||
|
|||||||
+5
-5
@@ -94,7 +94,7 @@ type ObjectMeta struct {
|
|||||||
// Null for lists.
|
// Null for lists.
|
||||||
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
|
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||||
// +optional
|
// +optional
|
||||||
CreationTimestamp time.Time `json:"creationTimestamp,omitempty"`
|
CreationTimestamp time.Time `json:"creationTimestamp"`
|
||||||
|
|
||||||
// DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This
|
// DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This
|
||||||
// field is set by the server when a graceful deletion is requested by the user, and is not
|
// field is set by the server when a graceful deletion is requested by the user, and is not
|
||||||
@@ -169,14 +169,14 @@ type Event struct {
|
|||||||
ObjectMeta `json:"metadata"`
|
ObjectMeta `json:"metadata"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Reason string `json:"reason,omitempty"`
|
Reason string `json:"reason,omitempty"`
|
||||||
Source EventSource `json:"source,omitempty"` // who is emitting this Event
|
Source EventSource `json:"source"` // who is emitting this Event
|
||||||
Type string `json:"type,omitempty"` // Normal or Warning
|
Type string `json:"type,omitempty"` // Normal or Warning
|
||||||
// InvolvedObject is the subject of the Event. `kubectl describe` will, for most object types, display any
|
// InvolvedObject is the subject of the Event. `kubectl describe` will, for most object types, display any
|
||||||
// currently present cluster Events matching the object (but you probably want to set UID for this to work).
|
// currently present cluster Events matching the object (but you probably want to set UID for this to work).
|
||||||
InvolvedObject ObjectReference `json:"involvedObject"`
|
InvolvedObject ObjectReference `json:"involvedObject"`
|
||||||
Count int32 `json:"count,omitempty"` // how many times Event was observed
|
Count int32 `json:"count,omitempty"` // how many times Event was observed
|
||||||
FirstTimestamp time.Time `json:"firstTimestamp,omitempty"`
|
FirstTimestamp time.Time `json:"firstTimestamp"`
|
||||||
LastTimestamp time.Time `json:"lastTimestamp,omitempty"`
|
LastTimestamp time.Time `json:"lastTimestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventSource includes a subset of fields from corev1.EventSource.
|
// EventSource includes a subset of fields from corev1.EventSource.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/mod/modfile"
|
"golang.org/x/mod/modfile"
|
||||||
@@ -26,13 +27,7 @@ func CheckGoModReplaces(args []string, watchedRemotes, allowedReplaceDirs []stri
|
|||||||
}
|
}
|
||||||
remoteLoc := args[1]
|
remoteLoc := args[1]
|
||||||
|
|
||||||
watched := false
|
watched := slices.Contains(watchedRemotes, remoteLoc)
|
||||||
for _, r := range watchedRemotes {
|
|
||||||
if r == remoteLoc {
|
|
||||||
watched = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !watched {
|
if !watched {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -69,13 +64,7 @@ func checkCommit(sha string, allowedReplaceDirs []string) error {
|
|||||||
if !modfile.IsDirectoryPath(r.New.Path) {
|
if !modfile.IsDirectoryPath(r.New.Path) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
allowed := false
|
allowed := slices.Contains(allowedReplaceDirs, r.New.Path)
|
||||||
for _, a := range allowedReplaceDirs {
|
|
||||||
if a == r.New.Path {
|
|
||||||
allowed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !allowed {
|
if !allowed {
|
||||||
return fmt.Errorf("go.mod contains replace from %v => %v", r.Old.Path, r.New.Path)
|
return fmt.Errorf("go.mod contains replace from %v => %v", r.Old.Path, r.New.Path)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-4
@@ -553,10 +553,7 @@ func computePrefixSplit(a, b netip.Prefix) (lastCommon netip.Prefix, aStride, bS
|
|||||||
panic("computePrefixSplit called with mismatched address families")
|
panic("computePrefixSplit called with mismatched address families")
|
||||||
}
|
}
|
||||||
|
|
||||||
minPrefixLen := a.Bits()
|
minPrefixLen := min(b.Bits(), a.Bits())
|
||||||
if b.Bits() < minPrefixLen {
|
|
||||||
minPrefixLen = b.Bits()
|
|
||||||
}
|
|
||||||
|
|
||||||
commonBits := commonBits(a.Addr(), b.Addr(), minPrefixLen)
|
commonBits := commonBits(a.Addr(), b.Addr(), minPrefixLen)
|
||||||
// We want to know how many 8-bit strides are shared between a and
|
// We want to know how many 8-bit strides are shared between a and
|
||||||
|
|||||||
@@ -671,10 +671,7 @@ func makeResponseOfSize(tb testing.TB, domain string, targetSize int, includeOPT
|
|||||||
if includeOPT {
|
if includeOPT {
|
||||||
baseSize += 11 // OPT record adds ~11 bytes
|
baseSize += 11 // OPT record adds ~11 bytes
|
||||||
}
|
}
|
||||||
estimatedRecords := (targetSize - baseSize) / bytesPerRecord
|
estimatedRecords := max((targetSize-baseSize)/bytesPerRecord, 1)
|
||||||
if estimatedRecords < 1 {
|
|
||||||
estimatedRecords = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start with estimated records and adjust
|
// Start with estimated records and adjust
|
||||||
txtLen := 200
|
txtLen := 200
|
||||||
@@ -741,10 +738,7 @@ func makeResponseOfSize(tb testing.TB, domain string, targetSize int, includeOPT
|
|||||||
// If we need too many records, increase TXT length instead
|
// If we need too many records, increase TXT length instead
|
||||||
txtLen = 255 // Max single TXT string length
|
txtLen = 255 // Max single TXT string length
|
||||||
bytesPerRecord = 280 // Adjusted estimate
|
bytesPerRecord = 280 // Adjusted estimate
|
||||||
estimatedRecords = (targetSize - baseSize) / bytesPerRecord
|
estimatedRecords = max((targetSize-baseSize)/bytesPerRecord, 1)
|
||||||
if estimatedRecords < 1 {
|
|
||||||
estimatedRecords = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -28,10 +28,7 @@ func maybeUnUTF16(bs []byte) []byte {
|
|||||||
// Can't be complete UTF-16.
|
// Can't be complete UTF-16.
|
||||||
return bs
|
return bs
|
||||||
}
|
}
|
||||||
checkLen := 20
|
checkLen := min(len(bs), 20)
|
||||||
if len(bs) < checkLen {
|
|
||||||
checkLen = len(bs)
|
|
||||||
}
|
|
||||||
zeroOff := bytes.IndexByte(bs[:checkLen], 0)
|
zeroOff := bytes.IndexByte(bs[:checkLen], 0)
|
||||||
if zeroOff == -1 {
|
if zeroOff == -1 {
|
||||||
return bs
|
return bs
|
||||||
|
|||||||
@@ -512,7 +512,7 @@ func TestRecentReportsRetainFullNetcheck(t *testing.T) {
|
|||||||
const tick = time.Minute
|
const tick = time.Minute
|
||||||
start := time.Unix(1700000000, 0)
|
start := time.Unix(1700000000, 0)
|
||||||
var lastFull time.Time // zero => first report is full, as in GetReport
|
var lastFull time.Time // zero => first report is full, as in GetReport
|
||||||
for i := 0; i < 60; i++ {
|
for i := range 60 {
|
||||||
now = start.Add(time.Duration(i) * tick)
|
now = start.Add(time.Duration(i) * tick)
|
||||||
|
|
||||||
// Mirror GetReport's full-vs-incremental decision.
|
// Mirror GetReport's full-vs-incremental decision.
|
||||||
|
|||||||
+1
-4
@@ -26,10 +26,7 @@ func parsePort(s mem.RO) int {
|
|||||||
// a.b.c.d.1234 or [a:b:c:d].1234
|
// a.b.c.d.1234 or [a:b:c:d].1234
|
||||||
i2 := mem.LastIndexByte(s, '.')
|
i2 := mem.LastIndexByte(s, '.')
|
||||||
|
|
||||||
i := i1
|
i := max(i2, i1)
|
||||||
if i2 > i {
|
|
||||||
i = i2
|
|
||||||
}
|
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
// no match; weird
|
// no match; weird
|
||||||
return -1
|
return -1
|
||||||
|
|||||||
@@ -323,11 +323,11 @@ func readMacosSameUserProof() (port int, token string, err error) {
|
|||||||
subStr := []byte(".tailscale.ipn.macos/sameuserproof-")
|
subStr := []byte(".tailscale.ipn.macos/sameuserproof-")
|
||||||
for bs.Scan() {
|
for bs.Scan() {
|
||||||
line := bs.Bytes()
|
line := bs.Bytes()
|
||||||
i := bytes.Index(line, subStr)
|
_, after, ok := bytes.Cut(line, subStr)
|
||||||
if i == -1 {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
f := strings.SplitN(string(line[i+len(subStr):]), "-", 2)
|
f := strings.SplitN(string(after), "-", 2)
|
||||||
if len(f) != 2 {
|
if len(f) != 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -2469,7 +2469,7 @@ type Oauth2Token struct {
|
|||||||
// If zero, TokenSource implementations will reuse the same
|
// If zero, TokenSource implementations will reuse the same
|
||||||
// token forever and RefreshToken or equivalent
|
// token forever and RefreshToken or equivalent
|
||||||
// mechanisms for that TokenSource will not be used.
|
// mechanisms for that TokenSource will not be used.
|
||||||
Expiry time.Time `json:"expiry,omitempty"`
|
Expiry time.Time `json:"expiry,omitzero"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeCapability represents a capability granted to the self node as listed in
|
// NodeCapability represents a capability granted to the self node as listed in
|
||||||
|
|||||||
@@ -808,7 +808,7 @@ func FuzzNodeIsRouter(f *testing.F) {
|
|||||||
decodePrefixes := func(t *testing.T, prefixes string) []netip.Prefix {
|
decodePrefixes := func(t *testing.T, prefixes string) []netip.Prefix {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
var out []netip.Prefix
|
var out []netip.Prefix
|
||||||
for _, p := range strings.Fields(prefixes) {
|
for p := range strings.FieldsSeq(prefixes) {
|
||||||
pfx, err := netip.ParsePrefix(p)
|
pfx, err := netip.ParsePrefix(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("skipping %q: %v", prefixes, err)
|
log.Printf("skipping %q: %v", prefixes, err)
|
||||||
@@ -1076,7 +1076,7 @@ func TestMarshalToRawMessageAndBack(t *testing.T) {
|
|||||||
Ports []int `json:"ports,omitempty"`
|
Ports []int `json:"ports,omitempty"`
|
||||||
ToggleOn bool `json:"toggleOn,omitempty"`
|
ToggleOn bool `json:"toggleOn,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Groups inner `json:"groups,omitempty"`
|
Groups inner `json:"groups"`
|
||||||
Addrs []netip.AddrPort `json:"addrs"`
|
Addrs []netip.AddrPort `json:"addrs"`
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -71,10 +72,8 @@ func TestListenSSH(t *testing.T) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, peer := range st.Peer {
|
for _, peer := range st.Peer {
|
||||||
for _, ip := range peer.TailscaleIPs {
|
if slices.Contains(peer.TailscaleIPs, clientIP) {
|
||||||
if ip == clientIP {
|
return nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors.New("clientNode not yet in srvNode's netmap")
|
return errors.New("clientNode not yet in srvNode's netmap")
|
||||||
|
|||||||
@@ -428,11 +428,11 @@ func waitForVMIP(t testing.TB, mac string, timeout time.Duration) (string, error
|
|||||||
var currentIP string
|
var currentIP string
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if strings.HasPrefix(line, "ip_address=") {
|
if after, ok := strings.CutPrefix(line, "ip_address="); ok {
|
||||||
currentIP = strings.TrimPrefix(line, "ip_address=")
|
currentIP = after
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "hw_address=") {
|
if after, ok := strings.CutPrefix(line, "hw_address="); ok {
|
||||||
hw := strings.TrimPrefix(line, "hw_address=")
|
hw := after
|
||||||
if strings.ToLower(hw) == leaseMAC && currentIP != "" {
|
if strings.ToLower(hw) == leaseMAC && currentIP != "" {
|
||||||
return currentIP, nil
|
return currentIP, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -872,7 +872,7 @@ func (e *Env) BringUpMullvadWGServer(n *Node, gw netip.Prefix, listenPort uint16
|
|||||||
e.t.Fatalf("BringUpMullvadWGServer(%s): %s: %s", n.name, res.Status, body)
|
e.t.Fatalf("BringUpMullvadWGServer(%s): %s: %s", n.name, res.Status, body)
|
||||||
}
|
}
|
||||||
var pubB64 string
|
var pubB64 string
|
||||||
for _, line := range strings.Split(string(body), "\n") {
|
for line := range strings.SplitSeq(string(body), "\n") {
|
||||||
if s, ok := strings.CutPrefix(strings.TrimSpace(line), "PUBKEY="); ok {
|
if s, ok := strings.CutPrefix(strings.TrimSpace(line), "PUBKEY="); ok {
|
||||||
pubB64 = s
|
pubB64 = s
|
||||||
break
|
break
|
||||||
@@ -2046,7 +2046,7 @@ func findKernelPath(goMod string) (string, error) {
|
|||||||
goModCache := strings.TrimSpace(string(goModCacheB))
|
goModCache := strings.TrimSpace(string(goModCacheB))
|
||||||
|
|
||||||
// Parse go.mod to find gokrazy-kernel version.
|
// Parse go.mod to find gokrazy-kernel version.
|
||||||
for _, line := range strings.Split(string(b), "\n") {
|
for line := range strings.SplitSeq(string(b), "\n") {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if strings.HasPrefix(line, "github.com/tailscale/gokrazy-kernel") {
|
if strings.HasPrefix(line, "github.com/tailscale/gokrazy-kernel") {
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
|
|||||||
+1
-1
@@ -74,7 +74,7 @@ func parseTrustedCIDRs(raw string) []netip.Prefix {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var prefixes []netip.Prefix
|
var prefixes []netip.Prefix
|
||||||
for _, s := range strings.Split(raw, ",") {
|
for s := range strings.SplitSeq(raw, ",") {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
if s == "" {
|
if s == "" {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -43,12 +43,7 @@ func (tb *tokenBucket) Get() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tb *tokenBucket) Refund(n int) {
|
func (tb *tokenBucket) Refund(n int) {
|
||||||
b := tb.remaining + n
|
tb.remaining = min(tb.remaining+n, tb.max)
|
||||||
if b > tb.max {
|
|
||||||
tb.remaining = tb.max
|
|
||||||
} else {
|
|
||||||
tb.remaining = b
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tb *tokenBucket) AdvanceTo(t time.Time) {
|
func (tb *tokenBucket) AdvanceTo(t time.Time) {
|
||||||
|
|||||||
@@ -60,10 +60,7 @@ func (b *Backoff) BackOff(ctx context.Context, err error) {
|
|||||||
b.n++
|
b.n++
|
||||||
// n^2 backoff timer is a little smoother than the
|
// n^2 backoff timer is a little smoother than the
|
||||||
// common choice of 2^n.
|
// common choice of 2^n.
|
||||||
d := time.Duration(b.n*b.n) * 10 * time.Millisecond
|
d := min(time.Duration(b.n*b.n)*10*time.Millisecond, b.maxBackoff)
|
||||||
if d > b.maxBackoff {
|
|
||||||
d = b.maxBackoff
|
|
||||||
}
|
|
||||||
// Randomize the delay between 0.5-1.5 x msec, in order
|
// Randomize the delay between 0.5-1.5 x msec, in order
|
||||||
// to prevent accidental "thundering herd" problems.
|
// to prevent accidental "thundering herd" problems.
|
||||||
d = time.Duration(float64(d) * (rand.Float64() + 0.5))
|
d = time.Duration(float64(d) * (rand.Float64() + 0.5))
|
||||||
|
|||||||
Reference in New Issue
Block a user