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>
71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
// waste-daemon: the local peer process.
|
|
// Run one of these on each friend's machine.
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/waste-go/internal/crypto"
|
|
"github.com/waste-go/internal/ipc"
|
|
"github.com/waste-go/internal/invite"
|
|
"github.com/waste-go/internal/netmgr"
|
|
)
|
|
|
|
func main() {
|
|
dataDir := flag.String("data-dir", "~/.waste", "path to identity/config directory")
|
|
alias := flag.String("alias", "anon", "display name shown to peers (advisory only)")
|
|
ipcPort := flag.Int("ipc-port", 17337, "port for local IPC (UI connects here)")
|
|
anchorURL := flag.String("anchor", "", "anchor WebSocket URL, e.g. ws://your-vps:17339/ws")
|
|
shareDir := flag.String("share-dir", "", "directory to share with peers on the network")
|
|
joinInvite := flag.String("join", "", "waste: invite string — sets anchor URL and auto-joins the network on startup")
|
|
flag.Parse()
|
|
|
|
dir := expandHome(*dataDir)
|
|
|
|
id, err := crypto.LoadOrCreate(dir, *alias)
|
|
if err != nil {
|
|
log.Fatalf("identity: %v", err)
|
|
}
|
|
log.Printf("daemon: local peer id: %s alias: %s", id.PeerID().Short(), id.Alias)
|
|
|
|
// --join overrides/sets the anchor URL and triggers an auto-join.
|
|
var autoJoinNetwork string
|
|
if *joinInvite != "" {
|
|
inv, err := invite.Decode(*joinInvite)
|
|
if err != nil {
|
|
log.Fatalf("invalid invite: %v", err)
|
|
}
|
|
*anchorURL = inv.Anchor
|
|
autoJoinNetwork = inv.Network
|
|
log.Printf("daemon: invite decoded — anchor=%s network=%s", inv.Anchor, inv.Network)
|
|
}
|
|
|
|
mgr := netmgr.New(netmgr.Config{
|
|
MasterIdentity: id,
|
|
StoreDir: dir,
|
|
AnchorURL: *anchorURL,
|
|
ShareDir: expandHome(*shareDir),
|
|
})
|
|
|
|
if autoJoinNetwork != "" {
|
|
if _, err := mgr.Join(autoJoinNetwork, ""); err != nil {
|
|
log.Fatalf("auto-join: %v", err)
|
|
}
|
|
}
|
|
|
|
if err := ipc.Run(mgr, *ipcPort); err != nil {
|
|
log.Fatalf("ipc: %v", err)
|
|
}
|
|
}
|
|
|
|
func expandHome(path string) string {
|
|
if len(path) >= 2 && path[:2] == "~/" {
|
|
if home, err := os.UserHomeDir(); err == nil {
|
|
return home + path[1:]
|
|
}
|
|
}
|
|
return path
|
|
}
|