Find storage and AI servers on the tailnet, not only over mDNS

Ports CoreDesktop's 16e5a9c.

configure storage and configure ai-servers now also ask the other online
computers on the Core's tailnet, so a laptop away from home still finds
the MiniServer and the LLM box. A machine found both ways is listed
once, by its tailnet name, and tailnet servers mount at /mnt/<short name>.

Smoketest: 45-tailnet, with a stand-in tailscale.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 18:58:18 -07:00
co-authored by Claude Opus 5.5
parent 1445ad7bb1
commit dfb43c866c
7 changed files with 195 additions and 23 deletions
+12 -6
View File
@@ -14,6 +14,7 @@ SANDBOX_CONF="$CONF_DIR/sandbox/base.json"
CLAUDE_SETTINGS="$HOME/.claude/settings.json"
OPENCODE_CONF="$HOME/.config/opencode/opencode.json"
source "$CONNECTOR/configure.d/lib/mdns.sh"
source "$CONNECTOR/configure.d/lib/tailnet.sh"
source "$CONNECTOR/configure.d/lib/json.sh"
# Ports LLM servers listen on by default, and who uses each. All of them answer
@@ -42,13 +43,13 @@ server_kind() {
fi
}
# The LLM servers on the network: "host:port|models" per line. mDNS finds the
# machines, but LLM servers don't announce themselves on it, so each machine
# is asked on the usual ports.
# The LLM servers on the network: "host:port|models" per line. mDNS and the
# tailnet find the machines, but LLM servers don't announce themselves, so
# each machine is asked on the usual ports.
find_servers() {
local dir host port
dir="$(mktemp -d)" || return 1
for host in $(mdns_hosts); do
for host in $(with_tailnet_hosts "$(mdns_hosts)"); do
for port in "${LLM_PORTS[@]}"; do
(server_models "$host:$port" | wc -l > "$dir/$host:$port") &
done
@@ -200,17 +201,22 @@ remove_server() {
# Find servers on the network and add the one you choose
find_and_add() {
local servers server models choice i
echo "Looking for LLM servers on your network..."
if tailnet_joined; then
echo "Looking for LLM servers on your network and the Core's (Tailscale)..."
else
echo "Looking for LLM servers on your network..."
fi
mapfile -t servers < <(find_servers)
if [ ${#servers[@]} -eq 0 ]; then
echo "No LLM servers found. A server has to accept connections from other machines:"
echo "in Ollama's settings, turn on \"Expose Ollama to the network\" (or set OLLAMA_HOST=0.0.0.0);"
echo "in LM Studio, turn on \"Serve on Local Network\". Or enter its address instead."
tailnet_joined || echo "To find the Core's servers away from home too, run: configure tailscale"
return 0
fi
for i in "${!servers[@]}"; do
IFS='|' read -r server models <<< "${servers[$i]}"
printf ' %2d) %-28s %s, %s models\n' $((i + 1)) "$server" "$(server_kind "$server")" "$models"
printf ' %2d) %-36s %s, %s models\n' $((i + 1)) "$server" "$(server_kind "$server")" "$models"
done
read -rp "Which server? " choice
if ! [[ "$choice" =~ ^[0-9]+$ ]] || (( choice < 1 || choice > ${#servers[@]} )); then
+36 -14
View File
@@ -13,6 +13,7 @@ STORAGE_CONF="$CONF_DIR/storage"
# Passwords for SMB shares, readable only by root, which mounts them
SMB_CREDENTIALS="/etc/federated-connector/smb"
source "$CONNECTOR/configure.d/lib/mdns.sh"
source "$CONNECTOR/configure.d/lib/tailnet.sh"
source "$CONNECTOR/configure.d/lib/sidebar.sh"
is_configured() {
@@ -26,10 +27,11 @@ slug() {
echo "${s:-share}"
}
# /mnt/<host>[-<name>], with -2, -3... if that's taken
# /mnt/<host>[-<name>], with -2, -3... if that's taken. The host is its short
# name: box.local and box.tail.example are both /mnt/box.
mount_point() {
local base n=2 point
base="/mnt/$(slug "${1%.local}")"
base="/mnt/$(slug "$(short_host "$1")")"
[ -n "$2" ] && base="$base-$(slug "$2")"
point="$base"
while [ -e "$point" ] || grep -qsF "|$point" "$STORAGE_CONF"; do
@@ -101,7 +103,7 @@ add_smb() {
smb_fstab_line "$source" "$point" "$credentials" | sudo tee -a /etc/fstab > /dev/null || return 1
sudo systemctl daemon-reload || return 1
sudo systemctl restart "$(systemd-escape -p --suffix=automount "$point")" || return 1
finish_add smb "$source" "$point" "$share on ${host%.local}"
finish_add smb "$source" "$point" "$share on $(short_host "$host")"
}
remove_smb() {
@@ -177,7 +179,7 @@ add_sftp() {
sftp_unit "$source" "$point" > "$HOME/.config/systemd/user/$unit" || return 1
systemctl --user daemon-reload
systemctl --user enable --now "$unit" || return 1
finish_add sftp "$source" "$point" "${host%.local}${path:+ $(basename "$path")}"
finish_add sftp "$source" "$point" "$(short_host "$host")${path:+ $(basename "$path")}"
}
remove_sftp() {
@@ -219,30 +221,50 @@ remove_storage() {
echo "$point is no longer mounted."
}
# The file servers on the network: "kind|host|name" per line
# The file servers on the network: "kind|host|name" per line. Machines on the
# Core's tailnet don't announce anything there, so each is asked on the SFTP
# (22) and SMB (445) ports; one also found over mDNS is listed by its tailnet
# name only. A port that answers isn't proof, but add_sftp and add_smb say
# what's wrong if it isn't the server they expect.
find_storage() {
local own name type host
local own name type host tailnet shorts
own="$(mdns_own_host)"
mdns_services | while IFS='|' read -r name type host _; do
[[ "${host,,}" == "${own,,}" ]] && continue
case "$type" in
_smb._tcp) echo "smb|$host|$name" ;;
_sftp-ssh._tcp) echo "sftp|$host|$name" ;;
esac
done | sort -u
tailnet="$(tailnet_hosts)"
shorts="$(for host in $tailnet; do short_host "$host"; done)"
{
mdns_services | while IFS='|' read -r name type host _; do
[[ "${host,,}" == "${own,,}" ]] && continue
grep -qixF "$(short_host "$host")" <<< "$shorts" && continue
case "$type" in
_smb._tcp) echo "smb|$host|$name" ;;
_sftp-ssh._tcp) echo "sftp|$host|$name" ;;
esac
done
for host in $tailnet; do
( port_open "$host" 22 && echo "sftp|$host|$(short_host "$host")"
port_open "$host" 445 && echo "smb|$host|$(short_host "$host")" ) &
done
wait
} | sort -u
}
find_and_add() {
local found kind host name choice i
echo "Looking for shared folders on your network..."
if tailnet_joined; then
echo "Looking for shared folders on your network and the Core's (Tailscale)..."
else
echo "Looking for shared folders on your network..."
fi
mapfile -t found < <(find_storage)
if [ ${#found[@]} -eq 0 ]; then
echo "Nothing found. A Mac shares folders over SMB once File Sharing is on (System Settings >"
echo "General > Sharing). Or enter the address instead."
tailnet_joined || echo "To find the Core's servers away from home too, run: configure tailscale"
return 0
fi
for i in "${!found[@]}"; do
IFS='|' read -r kind host name <<< "${found[$i]}"
is_tailnet_host "$host" && host="$(short_host "$host") (Tailscale)"
printf ' %2d) %-26s %s\n' $((i + 1)) "$host" "$( [ "$kind" = smb ] && echo "SMB shared folders" || echo "SFTP (over SSH)")"
done
read -rp "Which? " choice
+62
View File
@@ -0,0 +1,62 @@
#!/bin/bash
#
# Purpose : Find the other machines on the Core's tailnet, for the configure.d
# items that find servers (storage, ai-servers) beyond the LAN that
# mDNS reaches. Source this file.
# true if this machine is on a tailnet now
tailnet_joined() {
command -v tailscale > /dev/null || return 1
tailscale status --json 2> /dev/null | jq -e '.BackendState == "Running"' > /dev/null 2>&1
}
# The other online computers on the tailnet, one MagicDNS name per line
# (box.tail.example). Phones and tablets are left out: nobody serves files or
# models from them, and each one costs a probe. Nothing if Tailscale isn't
# installed or running.
tailnet_hosts() {
command -v tailscale > /dev/null || return 0
tailscale status --json 2> /dev/null \
| jq -r 'select(.BackendState == "Running") | .Peer // {} | .[]
| select(.Online)
| select(.OS | IN("linux", "macOS", "windows", "freebsd"))
| .DNSName // "" | rtrimstr(".") | select(. != "")' 2> /dev/null \
| sort -u
}
# true if host $1 takes TCP connections on port $2 within 2 seconds
port_open() {
timeout 2 bash -c ': < "/dev/tcp/$1/$2"' _ "$1" "$2" 2> /dev/null
}
# The name to show and to use in paths: box.tail.example -> box, box.local ->
# box. An IP address stays whole.
short_host() {
if [[ "$1" =~ ^[0-9.]+$ || "$1" == *:* ]]; then
echo "$1"
else
echo "${1%%.*}"
fi
}
# true if $1 is a tailnet name rather than a .local one or an address
is_tailnet_host() {
[[ "$1" == *.* && "$1" != *.local && ! "$1" =~ ^[0-9.]+$ && "$1" != *:* ]]
}
# The tailnet's machines, then the hosts in $1 (one per line, e.g. from
# mdns_hosts) that aren't on the tailnet too. A machine at home is both
# box.local and box.tail.example; its tailnet name keeps working away from home.
with_tailnet_hosts() {
local host key
local -A seen=()
for host in $(tailnet_hosts); do
key="$(short_host "${host,,}")"
seen[$key]=1
echo "$host"
done
for host in $1; do
key="$(short_host "${host,,}")"
[ -n "${seen[$key]:-}" ] || echo "$host"
done
}