probe remembered users instead of duplicating the bare host
429 unmodified linesExpand all43043143243343443443543643643743843944053 unmodified lines429 unmodified linesExpand all var offline []remote.Peer if os.Getenv("TOBI_OFFLINE") == "1" { offline = lo.Reject(peers, func(p remote.Peer, _ int) bool { return p.Online || strings.EqualFold(p.Name, self) }) } // a host with several known users gets one probing row per user // one probing row per user; bare hosts probe only when no user is known for _, p := range online { for _, dest := range remote.KnownDests(p.Name) { for _, dest := range remote.ProbeDests(p.Name) { m.rows = append(m.rows, hostRow{name: dest, probing: true}) } } for _, p := range offline {53 unmodified lines58 unmodified lines596061626364656667686970717273747576777879802 unmodified lines58 unmodified lines t.Fatalf("KnownDests volta = %v, want %v", got, want) }}
func TestProbeDestsUsersOnlyWhenKnown(t *testing.T) { withHostMap(t, "") if got := ProbeDests("freshhost"); !slices.Equal(got, []string{"freshhost"}) { t.Fatalf("ProbeDests unknown = %v", got) } RememberHost("dawn@caladon") RememberHost("root@caladon") // most recent first got := ProbeDests("caladon") want := []string{"root@caladon", "dawn@caladon"} if !slices.Equal(got, want) { t.Fatalf("ProbeDests = %v, want %v", got, want) }}
func TestHostDestUnknownStaysBare(t *testing.T) { withHostMap(t, "") if d := hostDest("unknownhost"); d != "unknownhost" { t.Fatalf("hostDest = %q, want the host unchanged", d)2 unmodified lines126 unmodified linesExpand all127128129130131132133134135136137138139140131141142143144145146147138148149150151152334 unmodified linesExpand all126 unmodified linesExpand all return d != "" && d != host })...))}
// ProbeDests is the list of destinations worth probing for a host: every// remembered user when one exists, the bare host otherwisefunc ProbeDests(host string) []string { dests := KnownDests(host) if len(dests) > 1 { return dests[1:] } return dests}
// QueryHost lists a host's sessions across every known destination,// QueryHost lists a host's sessions across every probed destination,// deduplicated by bare host and idfunc QueryHost(ctx context.Context, host string) []session.Session { bare := host if _, b, ok := strings.Cut(host, "@"); ok { bare = b } dests := KnownDests(bare) dests := ProbeDests(bare) // an explicitly addressed user is probed even when never remembered if host != bare { dests = lo.Uniq(append([]string{host}, dests...)) }334 unmodified linesExpand all