Replace the original raw-TCP peer connections and Blowfish/RSA-era design with the YAW/2 protocol stack: Transport - internal/mesh/peer.go: raw TCP + manual ECDH replaced with pion/webrtc DataChannels (ICE, DTLS, SCTP). Peers negotiate via sealed offer/answer/ candidate exchange rather than direct dialling. - internal/nat: deleted — ICE subsumes everything this package was going to do. Signaling - cmd/anchor: new WebSocket signaling server (replaces cmd/relay). Verifies Ed25519 challenge/join signatures, routes opaque nacl/box blobs, broadcasts peer-join/peer-leave events. Never sees plaintext signaling content. - internal/anchor: new anchor client. Manages PeerConnection lifecycle, decides offerer by peer-id comparison, seals/opens signaling payloads with nacl/box, implements mesh.Anchor. Crypto (internal/crypto) - PeerID encoding: base64url → lowercase hex (64 chars, YAW/2 §2). - Sign/Verify: hex signatures throughout. - Added CurvePublicKey/CurvePrivateKey: X25519 keys derived from Ed25519 identity via Montgomery conversion (filippo.io/edwards25519), matching libsodium's crypto_sign_ed25519_*_to_curve25519. - Added SignalingBox/SignalingOpen: nacl/box (XSalsa20-Poly1305) seal/open for signaling payloads. Wire types (internal/proto) - ChatMessage gains Mid (random 16-byte hex) for mesh deduplication (§8). - FileChunk removed from PeerMessage — chunks go on a separate binary DataChannel labelled "f:<xid>"; FileDone added. - New types: SignalingPayload, AnchorMessage, HelloMessage, HelloBindString. - PeerID.Short() now returns first 16 hex chars grouped in 4s. - IPC: CmdConnect removed; CmdJoinNetwork/CmdLeaveNetwork added; EvtSessionReady added (fires when DataChannel opens and hello is received). IPC (internal/ipc) - join_network/leave_network replace connect (direct TCP dial). - Network joins are context-scoped: leave_network or client disconnect cancels the anchor connection cleanly. README updated to reflect new project layout, getting-started commands, IPC protocol, and roadmap state. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
// waste-daemon: the local peer process.
|
|
// Run one of these on each friend's machine.
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/waste-go/internal/anchor"
|
|
"github.com/waste-go/internal/crypto"
|
|
"github.com/waste-go/internal/ipc"
|
|
"github.com/waste-go/internal/mesh"
|
|
"github.com/waste-go/internal/proto"
|
|
)
|
|
|
|
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")
|
|
flag.Parse()
|
|
|
|
id, err := crypto.LoadOrCreate(expandHome(*dataDir), *alias)
|
|
if err != nil {
|
|
log.Fatalf("identity: %v", err)
|
|
}
|
|
log.Printf("daemon: local peer id: %s alias: %s", id.PeerID().Short(), id.Alias)
|
|
|
|
m := mesh.New(id)
|
|
|
|
// joinFn is passed to the IPC layer; it's called when the UI sends join_network.
|
|
joinFn := func(ctx context.Context, networkName string) {
|
|
if *anchorURL == "" {
|
|
log.Printf("daemon: join_network: no -anchor flag set")
|
|
m.Emit(proto.IpcMessage{Type: proto.EvtError, ErrorMessage: "no anchor configured — start daemon with -anchor <url>"})
|
|
return
|
|
}
|
|
log.Printf("daemon: joining network %q via %s", networkName, *anchorURL)
|
|
anchor.Run(ctx, *anchorURL, networkName, id, m)
|
|
log.Printf("daemon: left network %q", networkName)
|
|
}
|
|
|
|
if err := ipc.Run(m, *ipcPort, joinFn); 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
|
|
}
|
|
|