2026-06-21 16:14:07 +02:00
|
|
|
// Package ipc implements the local IPC server.
|
|
|
|
|
// The UI (or any local tool) connects to 127.0.0.1:17337 and speaks
|
|
|
|
|
// newline-delimited JSON: send IpcMessage commands, receive IpcMessage events.
|
|
|
|
|
package ipc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
"context"
|
|
|
|
|
"crypto/rand"
|
|
|
|
|
"encoding/hex"
|
2026-06-21 16:14:07 +02:00
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"net"
|
2026-06-21 17:55:28 +02:00
|
|
|
"sync"
|
2026-06-21 16:14:07 +02:00
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2026-06-21 18:56:24 +02:00
|
|
|
"github.com/waste-go/internal/invite"
|
2026-06-21 16:14:07 +02:00
|
|
|
"github.com/waste-go/internal/mesh"
|
|
|
|
|
"github.com/waste-go/internal/proto"
|
|
|
|
|
)
|
|
|
|
|
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
// JoinFunc is called when the UI issues a join_network command.
|
|
|
|
|
type JoinFunc func(ctx context.Context, networkName string)
|
|
|
|
|
|
2026-06-21 16:14:07 +02:00
|
|
|
// Run starts the IPC listener. Blocks until the listener fails.
|
2026-06-21 18:56:24 +02:00
|
|
|
// anchorURL is the configured anchor WebSocket URL (used for invite generation).
|
2026-06-21 17:55:28 +02:00
|
|
|
// Network join/leave state is daemon-scoped (shared across all IPC clients).
|
2026-06-21 18:56:24 +02:00
|
|
|
func Run(m *mesh.Mesh, port int, anchorURL string, join JoinFunc) error {
|
2026-06-21 16:14:07 +02:00
|
|
|
addr := fmt.Sprintf("127.0.0.1:%d", port)
|
|
|
|
|
ln, err := net.Listen("tcp", addr)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("ipc listen on %s: %w", addr, err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("ipc: listening on %s", addr)
|
|
|
|
|
|
2026-06-21 18:56:24 +02:00
|
|
|
// networkCancel / networkName are shared across all clients — any client
|
|
|
|
|
// can join/leave, and the join persists after the commanding client disconnects.
|
2026-06-21 17:55:28 +02:00
|
|
|
var (
|
|
|
|
|
networkMu sync.Mutex
|
|
|
|
|
networkCancel context.CancelFunc
|
2026-06-21 18:56:24 +02:00
|
|
|
networkName string
|
2026-06-21 17:55:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
doJoin := func(name string) {
|
|
|
|
|
networkMu.Lock()
|
|
|
|
|
if networkCancel != nil {
|
|
|
|
|
networkCancel()
|
|
|
|
|
}
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
networkCancel = cancel
|
2026-06-21 18:56:24 +02:00
|
|
|
networkName = name
|
2026-06-21 17:55:28 +02:00
|
|
|
networkMu.Unlock()
|
|
|
|
|
go join(ctx, name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
doLeave := func() {
|
|
|
|
|
networkMu.Lock()
|
|
|
|
|
if networkCancel != nil {
|
|
|
|
|
networkCancel()
|
|
|
|
|
networkCancel = nil
|
2026-06-21 18:56:24 +02:00
|
|
|
networkName = ""
|
2026-06-21 17:55:28 +02:00
|
|
|
}
|
|
|
|
|
networkMu.Unlock()
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 18:56:24 +02:00
|
|
|
currentNetwork := func() string {
|
|
|
|
|
networkMu.Lock()
|
|
|
|
|
defer networkMu.Unlock()
|
|
|
|
|
return networkName
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 16:14:07 +02:00
|
|
|
for {
|
|
|
|
|
conn, err := ln.Accept()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("ipc accept: %w", err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("ipc: UI client connected from %s", conn.RemoteAddr())
|
2026-06-21 18:56:24 +02:00
|
|
|
go handleClient(conn, m, anchorURL, currentNetwork, doJoin, doLeave)
|
2026-06-21 16:14:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 18:56:24 +02:00
|
|
|
func handleClient(conn net.Conn, m *mesh.Mesh, anchorURL string, currentNetwork func() string, doJoin func(string), doLeave func()) {
|
2026-06-21 16:14:07 +02:00
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
|
|
events := m.Subscribe()
|
|
|
|
|
defer m.Unsubscribe(events)
|
|
|
|
|
|
|
|
|
|
writeCh := make(chan []byte, 128)
|
2026-06-21 17:55:28 +02:00
|
|
|
done := make(chan struct{})
|
2026-06-21 16:14:07 +02:00
|
|
|
|
2026-06-21 17:55:28 +02:00
|
|
|
// Writer goroutine — sole owner of the write side of the connection.
|
2026-06-21 16:14:07 +02:00
|
|
|
go func() {
|
|
|
|
|
w := bufio.NewWriter(conn)
|
|
|
|
|
for line := range writeCh {
|
|
|
|
|
line = append(line, '\n')
|
|
|
|
|
if _, err := w.Write(line); err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.Flush()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
2026-06-21 17:55:28 +02:00
|
|
|
// Event pusher — forwards mesh events to the UI client.
|
|
|
|
|
// recover() guards against the rare race where writeCh is closed while a
|
|
|
|
|
// send is in flight (closed channel panics even inside select).
|
2026-06-21 16:14:07 +02:00
|
|
|
go func() {
|
2026-06-21 17:55:28 +02:00
|
|
|
defer func() { recover() }() //nolint:errcheck
|
|
|
|
|
for {
|
2026-06-21 16:14:07 +02:00
|
|
|
select {
|
2026-06-21 17:55:28 +02:00
|
|
|
case evt, ok := <-events:
|
|
|
|
|
if !ok {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
line, err := json.Marshal(evt)
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
select {
|
|
|
|
|
case writeCh <- line:
|
|
|
|
|
case <-done:
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
case <-done:
|
|
|
|
|
return
|
2026-06-21 16:14:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
2026-06-21 17:55:28 +02:00
|
|
|
send := func(msg proto.IpcMessage) {
|
|
|
|
|
defer func() { recover() }() //nolint:errcheck
|
|
|
|
|
line, err := json.Marshal(msg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
select {
|
|
|
|
|
case writeCh <- line:
|
|
|
|
|
case <-done:
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send(proto.IpcMessage{
|
2026-06-21 16:14:07 +02:00
|
|
|
Type: proto.EvtStateSnapshot,
|
|
|
|
|
LocalPeer: ptr(m.Identity.PeerInfo()),
|
|
|
|
|
ConnectedPeers: m.ConnectedPeers(),
|
|
|
|
|
Rooms: []string{"general"},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(conn)
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
var cmd proto.IpcMessage
|
|
|
|
|
if err := json.Unmarshal(scanner.Bytes(), &cmd); err != nil {
|
|
|
|
|
log.Printf("ipc: bad command: %v", err)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
switch cmd.Type {
|
|
|
|
|
|
|
|
|
|
case proto.CmdSendMessage:
|
|
|
|
|
msg := &proto.ChatMessage{
|
|
|
|
|
Mid: randomHex(16),
|
|
|
|
|
ID: uuid.NewString(),
|
|
|
|
|
From: m.Identity.PeerID(),
|
|
|
|
|
To: cmd.To,
|
|
|
|
|
Room: cmd.Room,
|
|
|
|
|
Body: cmd.Body,
|
|
|
|
|
SentAt: time.Now(),
|
|
|
|
|
}
|
|
|
|
|
payload, err := json.Marshal(proto.PeerMessage{Type: proto.MsgChat, Chat: msg})
|
2026-06-21 16:14:07 +02:00
|
|
|
if err != nil {
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
continue
|
2026-06-21 16:14:07 +02:00
|
|
|
}
|
2026-06-21 18:13:27 +02:00
|
|
|
if cmd.To != nil {
|
|
|
|
|
// DM — send only to the named recipient.
|
|
|
|
|
m.SendTo(*cmd.To, payload)
|
|
|
|
|
} else {
|
|
|
|
|
m.Broadcast(payload)
|
|
|
|
|
}
|
2026-06-21 18:04:42 +02:00
|
|
|
m.SaveMessage(msg)
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
m.Emit(proto.IpcMessage{Type: proto.EvtMessageReceived, Message: msg})
|
2026-06-21 16:14:07 +02:00
|
|
|
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
case proto.CmdJoinNetwork:
|
|
|
|
|
if cmd.NetworkName == "" {
|
2026-06-21 17:55:28 +02:00
|
|
|
send(errMsg("join_network: network_name is required"))
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
continue
|
|
|
|
|
}
|
2026-06-21 17:55:28 +02:00
|
|
|
doJoin(cmd.NetworkName)
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
|
|
|
|
|
case proto.CmdLeaveNetwork:
|
2026-06-21 17:55:28 +02:00
|
|
|
doLeave()
|
2026-06-21 16:14:07 +02:00
|
|
|
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
case proto.CmdGetState:
|
2026-06-21 17:55:28 +02:00
|
|
|
send(proto.IpcMessage{
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
Type: proto.EvtStateSnapshot,
|
|
|
|
|
LocalPeer: ptr(m.Identity.PeerInfo()),
|
|
|
|
|
ConnectedPeers: m.ConnectedPeers(),
|
|
|
|
|
Rooms: []string{"general"},
|
|
|
|
|
})
|
2026-06-21 16:14:07 +02:00
|
|
|
|
2026-06-21 19:07:11 +02:00
|
|
|
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())))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-21 18:56:24 +02:00
|
|
|
case proto.CmdGenerateInvite:
|
|
|
|
|
net := currentNetwork()
|
|
|
|
|
if net == "" {
|
|
|
|
|
send(errMsg("generate_invite: not currently joined to a network"))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if anchorURL == "" {
|
|
|
|
|
send(errMsg("generate_invite: daemon was started without -anchor flag"))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
inv, err := invite.Encode(anchorURL, net)
|
|
|
|
|
if err != nil {
|
|
|
|
|
send(errMsg(fmt.Sprintf("generate_invite: %v", err)))
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
send(proto.IpcMessage{Type: proto.EvtInviteGenerated, InviteString: inv})
|
|
|
|
|
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
case proto.CmdSendFile:
|
2026-06-21 17:55:28 +02:00
|
|
|
send(errMsg("file transfer not yet implemented"))
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
|
|
|
|
|
default:
|
2026-06-21 17:55:28 +02:00
|
|
|
send(errMsg(fmt.Sprintf("unknown command: %s", cmd.Type)))
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
}
|
2026-06-21 16:14:07 +02:00
|
|
|
}
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
|
2026-06-21 17:55:28 +02:00
|
|
|
close(done)
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
close(writeCh)
|
|
|
|
|
log.Printf("ipc: UI client disconnected")
|
2026-06-21 16:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func errMsg(s string) proto.IpcMessage {
|
|
|
|
|
return proto.IpcMessage{Type: proto.EvtError, ErrorMessage: s}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ptr[T any](v T) *T { return &v }
|
Migrate to YAW/2 protocol: WebRTC transport, anchor signaling, nacl/box crypto
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>
2026-06-21 17:48:14 +02:00
|
|
|
|
|
|
|
|
func randomHex(n int) string {
|
|
|
|
|
b := make([]byte, n)
|
|
|
|
|
rand.Read(b) //nolint:errcheck
|
|
|
|
|
return hex.EncodeToString(b)
|
|
|
|
|
}
|