Skip to content

Commit 0eef9fa

Browse files
committed
fix: show correct number of peers after switching accounts
1 parent 271d99a commit 0eef9fa

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

internal/domain/machine.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,14 @@ func (r *repository) ListMachineByTailnet(ctx context.Context, tailnetID uint64)
471471
return machines, nil
472472
}
473473

474-
func (r *repository) ListMachinePeers(ctx context.Context, tailnetID uint64, key string) (Machines, error) {
475-
var machines = []Machine{}
474+
func (r *repository) ListMachinePeers(ctx context.Context, tailnetID uint64, machineID uint64) (Machines, error) {
475+
var machines []Machine
476476

477477
tx := r.withContext(ctx).
478478
Preload("Tailnet").
479479
Joins("User").
480480
Joins("User.Account").
481-
Where("machines.tailnet_id = ? AND machines.machine_key <> ?", tailnetID, key).
481+
Where("machines.tailnet_id = ? AND machines.id <> ?", tailnetID, machineID).
482482
Order("machines.id asc").
483483
Find(&machines)
484484

internal/domain/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Repository interface {
6767
CountMachineByTailnet(ctx context.Context, tailnetID uint64) (int64, error)
6868
DeleteMachineByTailnet(ctx context.Context, tailnetID uint64) error
6969
DeleteMachineByUser(ctx context.Context, userID uint64) error
70-
ListMachinePeers(ctx context.Context, tailnetID uint64, key string) (Machines, error)
70+
ListMachinePeers(ctx context.Context, tailnetID uint64, machineID uint64) (Machines, error)
7171
ListInactiveEphemeralMachines(ctx context.Context, checkpoint time.Time) (Machines, error)
7272
SetMachineLastSeen(ctx context.Context, machineID uint64) error
7373

internal/mapping/poll_net_mapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (h *PollNetMapper) CreateMapResponse(ctx context.Context, delta bool) (*Map
8181
syncedPeerIDs := map[uint64]bool{}
8282

8383
if !h.req.OmitPeers {
84-
candidatePeers, err := h.repository.ListMachinePeers(ctx, m.TailnetID, m.MachineKey)
84+
candidatePeers, err := h.repository.ListMachinePeers(ctx, m.TailnetID, m.ID)
8585
if err != nil {
8686
return nil, err
8787
}

tests/switch_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestSwitchAccounts(t *testing.T) {
3434
require.NoError(t, node.WaitFor(tsn.Connected()))
3535
require.NoError(t, node.Check(tsn.HasUser("[email protected]")))
3636
require.NoError(t, node.Check(tsn.HasName("switch-1")))
37+
require.NoError(t, node.Check(tsn.PeerCount(1)))
3738

3839
machines := s.ListMachines(tailnet.Id)
3940
require.Equal(t, 2, len(machines))

0 commit comments

Comments
 (0)