feat: per-network share directories + isolation test

Each network now carries its own share dir, set at join_network time via
optional share_dir field or updated live with set_share_dir. The global
-share-dir daemon flag becomes a fallback default.

- proto: add ShareDir/DownloadDir to NetworkInfo and IpcMessage
- netmgr: Join accepts shareDir override; SetShareDir updates live
- ipc: wire join_network share_dir and set_share_dir command
- daemon: remove -share-dir from auto-join path (pass "" for default)
- test-network.sh: per-network join with share_dir; isolation verification
  section confirms alice/friends and alice/work share dirs are independent
- test-tui.sh: join_network with share_dir; peer IDs resolved after join

All tests pass: YAW/2.1 FS, share isolation, file transfer, persistence.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-22 15:13:26 +02:00
parent f437fe94f4
commit d02e18e212
7 changed files with 277 additions and 42 deletions

View File

@@ -117,12 +117,12 @@ func handleClient(conn net.Conn, mgr *netmgr.Manager) {
send(errMsg("join_network: network_name is required"))
continue
}
netID, err := mgr.Join(cmd.NetworkName)
netID, err := mgr.Join(cmd.NetworkName, cmd.ShareDir)
if err != nil {
send(errMsg(fmt.Sprintf("join_network: %v", err)))
continue
}
// network_joined event is emitted by Manager.Join; nothing extra needed.
// network_joined event (with share_dir) is emitted by Manager.Join.
_ = netID
case proto.CmdLeaveNetwork:
@@ -246,6 +246,17 @@ func handleClient(conn net.Conn, mgr *netmgr.Manager) {
InviteString: inv,
})
case proto.CmdSetShareDir:
n := mgr.Resolve(cmd.NetworkID)
if n == nil {
send(errMsg("set_share_dir: not joined to any network"))
continue
}
if !mgr.SetShareDir(n.ID, cmd.Path) {
send(errMsg("set_share_dir: network not found"))
continue
}
case proto.CmdSendFile:
n := mgr.Resolve(cmd.NetworkID)
if n == nil {
@@ -292,6 +303,8 @@ func stateSnapshot(mgr *netmgr.Manager) proto.IpcMessage {
NetworkID: n.ID,
NetworkName: n.Name,
LocalPeer: &pi,
ShareDir: n.Mesh.ShareDir,
DownloadDir: n.Mesh.DownloadDir,
})
}
msg.Networks = netInfos
@@ -322,7 +335,7 @@ func randomHex(n int) string {
// It joins the network before the IPC listener starts accepting clients.
func AutoJoin(ctx context.Context, mgr *netmgr.Manager, networkName string) {
_ = ctx // Manager owns the context internally
if _, err := mgr.Join(networkName); err != nil {
if _, err := mgr.Join(networkName, ""); err != nil {
log.Printf("ipc: auto-join %q failed: %v", networkName, err)
}
}