MCPcopy Create free account
hub / github.com/coder/wush / waitUntilHasPeerHasIP

Function waitUntilHasPeerHasIP

cmd/wush/ssh.go:133–175  ·  view source on GitHub ↗
(ctx context.Context, logF func(str string, args ...any), lc *tailscale.LocalClient)

Source from the content-addressed store, hash-verified

131}
132
133func 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
177func waitUntilHasP2P(ctx context.Context, logF func(str string, args ...any), lc *tailscale.LocalClient) error {
178 for {

Callers 3

cpCmdFunction · 0.85
portForwardCmdFunction · 0.85
sshCmdFunction · 0.85

Calls 1

CodeFunction · 0.92

Tested by

no test coverage detected