7c5ecfe50f
Add drive.go (build tag !ts_omit_drive): implements drive.FileSystemForRemote with a JS-backed handler. Streams request bodies chunk-by-chunk via readBodyChunk() and response bodies via write()/end() callbacks so no full-body buffering occurs regardless of file size. The handler is nil-safe: returns 404 until setDriveHandler() is called from JS. Add drive_stub.go (build tag ts_omit_drive): no-op stubs for stripped builds. Add peer.go: extract buildPeerAPIURL helper (previously inline in run()). Modify wasm_js.go: call initDriveForRemote before NewLocalBackend (SubSystem is set-once), expose setDriveHandler and listDrivePeers via wireDriveJS, and refactor the inline peerAPI URL logic to use buildPeerAPIURL. listDrivePeers mirrors native driveRemotesFromPeers: returns empty if DriveAccessEnabled() is false, then filters peers by PeerCapabilityTaildriveSharer using lb.PeerCaps(addr).HasCapability() (the live ACL-derived cap map). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/netip"
|
|
|
|
"tailscale.com/tailcfg"
|
|
)
|
|
|
|
// buildPeerAPIURL returns the HTTP base URL for a peer's peerAPI server,
|
|
// selecting IPv4 when available and falling back to IPv6. Returns an empty
|
|
// string if the peer advertises no reachable peerAPI port.
|
|
func buildPeerAPIURL(p tailcfg.NodeView, selfHave4, selfHave6 bool) string {
|
|
var pp4, pp6 uint16
|
|
for _, s := range p.Hostinfo().Services().All() {
|
|
switch s.Proto {
|
|
case tailcfg.PeerAPI4:
|
|
pp4 = s.Port
|
|
case tailcfg.PeerAPI6:
|
|
pp6 = s.Port
|
|
}
|
|
}
|
|
if selfHave4 && pp4 != 0 {
|
|
for _, a := range p.Addresses().All() {
|
|
if a.IsSingleIP() && a.Addr().Is4() {
|
|
return fmt.Sprintf("http://%v", netip.AddrPortFrom(a.Addr(), pp4))
|
|
}
|
|
}
|
|
}
|
|
if selfHave6 && pp6 != 0 {
|
|
for _, a := range p.Addresses().All() {
|
|
if a.IsSingleIP() && a.Addr().Is6() {
|
|
return fmt.Sprintf("http://%v", netip.AddrPortFrom(a.Addr(), pp6))
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|