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

@@ -198,6 +198,26 @@ func handleClient(conn net.Conn, m *mesh.Mesh, anchorURL string, currentNetwork
Rooms: []string{"general"},
})
case proto.CmdGetFileList:
if cmd.PeerID == nil || *cmd.PeerID == m.Identity.PeerID() {
// Local list — scan immediately.
send(proto.IpcMessage{
Type: proto.EvtFileList,
PeerID: ptr(m.Identity.PeerID()),
Files: m.ScanShareDir(),
})
} else {
// Remote list — send a request over the DataChannel.
// The response arrives as EvtFileList via the mesh event bus.
req, err := json.Marshal(proto.PeerMessage{Type: proto.MsgFileListReq})
if err != nil {
continue
}
if !m.SendTo(*cmd.PeerID, req) {
send(errMsg(fmt.Sprintf("get_file_list: peer %s not connected", (*cmd.PeerID).Short())))
}
}
case proto.CmdGenerateInvite:
net := currentNetwork()
if net == "" {