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:
@@ -240,10 +240,14 @@ type jsDrivePeer struct {
|
|||||||
Online *bool `json:"online,omitempty"`
|
Online *bool `json:"online,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// listDrivePeers returns a JSON array of peers that carry
|
// listDrivePeers returns a JSON array of peers that are online, have a
|
||||||
// PeerCapabilityTaildriveSharer. Returns an empty array if the local node
|
// reachable peerAPI and carry PeerCapabilityTaildriveSharer. Returns an empty
|
||||||
// does not have drive:access in its ACL (DriveAccessEnabled). This mirrors
|
// array if the local node does not have drive:access in its ACL
|
||||||
// the filtering in LocalBackend.driveRemotesFromPeers.
|
// (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 {
|
func (i *jsIPN) listDrivePeers() js.Value {
|
||||||
return makePromise(func() (any, error) {
|
return makePromise(func() (any, error) {
|
||||||
if !i.lb.DriveAccessEnabled() {
|
if !i.lb.DriveAccessEnabled() {
|
||||||
@@ -269,6 +273,13 @@ func (i *jsIPN) listDrivePeers() js.Value {
|
|||||||
|
|
||||||
peers := make([]jsDrivePeer, 0)
|
peers := make([]jsDrivePeer, 0)
|
||||||
for _, p := range nm.Peers {
|
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
|
// Check PeerCapabilityTaildriveSharer via the live PeerCaps map
|
||||||
// (derived from ACL rules), mirroring driveRemotesFromPeers.
|
// (derived from ACL rules), mirroring driveRemotesFromPeers.
|
||||||
hasCap := false
|
hasCap := false
|
||||||
@@ -281,7 +292,6 @@ func (i *jsIPN) listDrivePeers() js.Value {
|
|||||||
if !hasCap {
|
if !hasCap {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
peerURL := buildPeerAPIURL(p, selfHave4, selfHave6)
|
|
||||||
online := p.Online().Clone()
|
online := p.Online().Clone()
|
||||||
peers = append(peers, jsDrivePeer{
|
peers = append(peers, jsDrivePeer{
|
||||||
Name: p.DisplayName(false),
|
Name: p.DisplayName(false),
|
||||||
|
|||||||
Reference in New Issue
Block a user