(ctx context.Context, logF func(str string, args ...any), lc *tailscale.LocalClient)
| 131 | } |
| 132 | |
| 133 | func waitUntilHasPeerHasIP(ctx context.Context, logF func(str string, args ...any), lc *tailscale.LocalClient) (netip.Addr, error) { |
| 134 | for { |
| 135 | select { |
| 136 | case <-ctx.Done(): |
| 137 | return netip.Addr{}, ctx.Err() |
| 138 | case <-time.After(time.Second): |
| 139 | } |
| 140 | |
| 141 | stat, err := lc.Status(ctx) |
| 142 | if err != nil { |
| 143 | fmt.Println("error getting lc status:", err) |
| 144 | continue |
| 145 | } |
| 146 | |
| 147 | peers := stat.Peers() |
| 148 | if len(peers) == 0 { |
| 149 | logF("No peer yet") |
| 150 | continue |
| 151 | } |
| 152 | |
| 153 | logF("Received peer") |
| 154 | |
| 155 | peer, ok := stat.Peer[peers[0]] |
| 156 | if !ok { |
| 157 | logF("have peers but not found in map (developer error)") |
| 158 | continue |
| 159 | } |
| 160 | |
| 161 | if peer.Relay == "" { |
| 162 | logF("peer no relay") |
| 163 | continue |
| 164 | } |
| 165 | |
| 166 | logF("Peer active with relay %s", cliui.Code(peer.Relay)) |
| 167 | |
| 168 | if len(peer.TailscaleIPs) == 0 { |
| 169 | logF("peer has no ips (developer error)") |
| 170 | continue |
| 171 | } |
| 172 | |
| 173 | return peer.TailscaleIPs[0], nil |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | func waitUntilHasP2P(ctx context.Context, logF func(str string, args ...any), lc *tailscale.LocalClient) error { |
| 178 | for { |
no test coverage detected