Add file listing: share-dir flag, file_list_req/resp DataChannel messages

- proto: FileEntry, FileListResp types; MsgFileListReq/Resp msg types;
  CmdGetFileList + EvtFileList IPC types; Files field on IpcMessage
- mesh: ShareDir field + ScanShareDir(); on DataChannel open, auto-send
  MsgFileListReq to new peer; handle MsgFileListReq (scan + reply) and
  MsgFileListResp (emit EvtFileList to IPC subscribers)
- ipc: get_file_list command — own list returned immediately; remote peer
  list requested via DataChannel (response arrives as EvtFileList event)
- daemon: -share-dir flag wired to mesh.ShareDir
- test scripts: pass -share-dir /home/frejoh/Downloads/{alice,bob,charlie};
  test-network.sh verifies each peer's own file list via get_file_list
- FUTURE.md: document per-network share directories and multi-network design

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-21 19:07:11 +02:00
parent 1a5f416ee4
commit 8d3ca9d331
9 changed files with 160 additions and 20 deletions

View File

@@ -192,6 +192,7 @@ log "$ALICE_COLOR" "alice" "starting daemon (ipc :${ALICE_IPC})"
-data-dir "$DATA_ROOT/alice" \
-ipc-port "$ALICE_IPC" \
-anchor "$ANCHOR_URL" \
-share-dir "/home/frejoh/Downloads/alice" \
2> >(while IFS= read -r l; do echo -e "${ALICE_COLOR}${DIM}[alice] ${l}${RESET}"; done) &
PIDS+=($!)
@@ -201,6 +202,7 @@ log "$BOB_COLOR" "bob" "starting daemon (ipc :${BOB_IPC})"
-data-dir "$DATA_ROOT/bob" \
-ipc-port "$BOB_IPC" \
-anchor "$ANCHOR_URL" \
-share-dir "/home/frejoh/Downloads/bob" \
2> >(while IFS= read -r l; do echo -e "${BOB_COLOR}${DIM}[bob] ${l}${RESET}"; done) &
PIDS+=($!)
@@ -210,6 +212,7 @@ log "$CHARLIE_COLOR" "charlie" "starting daemon (ipc :${CHARLIE_IPC})"
-data-dir "$DATA_ROOT/charlie" \
-ipc-port "$CHARLIE_IPC" \
-anchor "$ANCHOR_URL" \
-share-dir "/home/frejoh/Downloads/charlie" \
2> >(while IFS= read -r l; do echo -e "${CHARLIE_COLOR}${DIM}[charlie]${l}${RESET}"; done) &
PIDS+=($!)
@@ -309,6 +312,27 @@ ipc "$ALICE_IPC" "$(jq -cn \
'{"type":"send_message","room":$room,"body":$body,"to":$to}')"
sleep 0.4
# ── file list check ───────────────────────────────────────────────────────────
echo ""
echo -e "${DIM}────────────────────────────────────────────────────────${RESET}"
echo -e "file listing"
echo -e "${DIM}────────────────────────────────────────────────────────${RESET}"
for peer_ipc in "$ALICE_IPC" "$BOB_IPC" "$CHARLIE_IPC"; do
peer_name=$([ "$peer_ipc" = "$ALICE_IPC" ] && echo "alice" || ([ "$peer_ipc" = "$BOB_IPC" ] && echo "bob" || echo "charlie"))
result=$(echo '{"type":"get_file_list"}' \
| timeout 2 nc 127.0.0.1 "$peer_ipc" 2>/dev/null \
| grep '"type":"file_list"' | head -1)
if [ -n "$result" ]; then
count=$(echo "$result" | jq '.files | length' 2>/dev/null || echo "?")
files=$(echo "$result" | jq -r '.files[].name' 2>/dev/null | tr '\n' ' ')
echo -e " ${BOLD}${peer_name}${RESET}: ${count} file(s) — ${files}"
else
echo -e " ${RED}${peer_name}: no file_list response${RESET}"
fi
done
sleep 0.5
# ── leave ─────────────────────────────────────────────────────────────────────
echo ""
echo -e "${DIM}────────────────────────────────────────────────────────${RESET}"