fix(tsconnect/wasm): filter offline and unreachable drive peers

listDrivePeers only checked PeerCapabilityTaildriveSharer, which is
usually granted to a whole group or tag, so it returned most of the
tailnet including offline peers and peers with no reachable peerAPI.
Apply the same conjunction as LocalBackend.driveRemotesFromPeers.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit was merged in pull request #18.
This commit is contained in:
2026-08-02 01:32:15 +00:00
co-authored by Claude
parent d94244830b
commit 7e9868f50e
+15 -5
View File
@@ -240,10 +240,14 @@ type jsDrivePeer struct {
Online *bool `json:"online,omitempty"`
}
// listDrivePeers returns a JSON array of peers that carry
// PeerCapabilityTaildriveSharer. Returns an empty array if the local node
// does not have drive:access in its ACL (DriveAccessEnabled). This mirrors
// the filtering in LocalBackend.driveRemotesFromPeers.
// listDrivePeers returns a JSON array of peers that are online, have a
// reachable peerAPI and carry PeerCapabilityTaildriveSharer. Returns an empty
// array if the local node does not have drive:access in its ACL
// (DriveAccessEnabled). This mirrors the filtering in
// LocalBackend.driveRemotesFromPeers.
//
// The cap means a peer is allowed to share with us, not that it currently
// exposes any share, so the result is a superset of the peers with shares.
func (i *jsIPN) listDrivePeers() js.Value {
return makePromise(func() (any, error) {
if !i.lb.DriveAccessEnabled() {
@@ -269,6 +273,13 @@ func (i *jsIPN) listDrivePeers() js.Value {
peers := make([]jsDrivePeer, 0)
for _, p := range nm.Peers {
if !p.Online().Get() {
continue
}
peerURL := buildPeerAPIURL(p, selfHave4, selfHave6)
if peerURL == "" {
continue
}
// Check PeerCapabilityTaildriveSharer via the live PeerCaps map
// (derived from ACL rules), mirroring driveRemotesFromPeers.
hasCap := false
@@ -281,7 +292,6 @@ func (i *jsIPN) listDrivePeers() js.Value {
if !hasCap {
continue
}
peerURL := buildPeerAPIURL(p, selfHave4, selfHave6)
online := p.Online().Clone()
peers = append(peers, jsDrivePeer{
Name: p.DisplayName(false),