mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-31 16:23:44 +00:00
use a views.Slice
This commit is contained in:
parent
66ecab9540
commit
c35c3d1194
@ -13,6 +13,7 @@ import (
|
||||
"tailscale.com/ipn"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
"tailscale.com/tsnet"
|
||||
"tailscale.com/types/views"
|
||||
"tailscale.com/util/set"
|
||||
)
|
||||
|
||||
@ -84,16 +85,13 @@ func (a *authorization) selfAllowed() bool {
|
||||
return a.peers.status.Self.Tags != nil && slices.Contains(a.peers.status.Self.Tags.AsSlice(), a.tag)
|
||||
}
|
||||
|
||||
func (a *authorization) allowedPeers() []*ipnstate.PeerStatus {
|
||||
func (a *authorization) allowedPeers() views.Slice[*ipnstate.PeerStatus] {
|
||||
if a.peers == nil {
|
||||
return nil
|
||||
return views.SliceOf([]*ipnstate.PeerStatus{})
|
||||
}
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if a.peers.allowedPeers == nil {
|
||||
return []*ipnstate.PeerStatus{}
|
||||
}
|
||||
return a.peers.allowedPeers
|
||||
return views.SliceOf(a.peers.allowedPeers)
|
||||
}
|
||||
|
||||
type peers struct {
|
||||
|
@ -93,7 +93,7 @@ func TestAuthUnrefreshed(t *testing.T) {
|
||||
t.Fatalf("never refreshed authorization, allowsHost: expected false, got true")
|
||||
}
|
||||
gotAllowedPeers := a.allowedPeers()
|
||||
if gotAllowedPeers != nil {
|
||||
if gotAllowedPeers.Len() != 0 {
|
||||
t.Fatalf("never refreshed authorization, allowedPeers: expected [], got %v", gotAllowedPeers)
|
||||
}
|
||||
if a.selfAllowed() != false {
|
||||
@ -144,8 +144,8 @@ func TestAuthAllowedPeers(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ps := a.allowedPeers()
|
||||
if len(ps) != 2 {
|
||||
t.Fatalf("expected: 2, got: %d", len(ps))
|
||||
if ps.Len() != 2 {
|
||||
t.Fatalf("expected: 2, got: %d", ps.Len())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import (
|
||||
"github.com/hashicorp/raft"
|
||||
"tailscale.com/ipn/ipnstate"
|
||||
"tailscale.com/tsnet"
|
||||
"tailscale.com/types/views"
|
||||
)
|
||||
|
||||
func addr(host string, port uint16) string {
|
||||
@ -268,9 +269,9 @@ type Consensus struct {
|
||||
// - We want to handle machines joining after start anyway.
|
||||
// - Not all tagged nodes tailscale believes are active are necessarily actually responsive right now,
|
||||
// so let each node opt in when able.
|
||||
func (c *Consensus) bootstrap(targets []*ipnstate.PeerStatus) error {
|
||||
log.Printf("Trying to find cluster: num targets to try: %d", len(targets))
|
||||
for _, p := range targets {
|
||||
func (c *Consensus) bootstrap(targets views.Slice[*ipnstate.PeerStatus]) error {
|
||||
log.Printf("Trying to find cluster: num targets to try: %d", targets.Len())
|
||||
for _, p := range targets.All() {
|
||||
if !p.Online {
|
||||
log.Printf("Trying to find cluster: tailscale reports not online: %s", p.TailscaleIPs[0])
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user