Add SQLite message and peer persistence (internal/store)
Each daemon writes to <data-dir>/messages.db on startup. Messages received or sent are stored immediately; duplicate mids (INSERT OR IGNORE) are safe to call multiple times. Peer aliases are upserted on peer_connected and again after hello verification when the real nick is known. Schema - messages(mid UNIQUE, room, from_peer, body, sent_at) — mid is the YAW/2 dedup key added in the proto migration; index on (room, sent_at) for efficient per-room queries. - peers(peer_id PK, alias, last_seen) — cache of every peer ever seen, used to resolve hex ids to names when peers are offline. Wiring - store.Open called in cmd/daemon/main.go, passed to mesh.New. - mesh.Mesh holds *store.Store (nil-safe; persistence is optional). - mesh.SaveMessage called in dispatchPeerMessage (incoming) and ipc CmdSendMessage (outgoing) so the local node's own messages are stored. - mesh.UpdatePeerAlias called after hello verification updates the alias with the verified nick rather than the placeholder short-id. Messages only accumulate from join time forward — no history replay to late-joining peers; each node's view starts from when it connected. test-network.sh: added SQLite verification block that queries each node's DB after the test and prints message + peer counts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
14
go.mod
14
go.mod
@@ -1,16 +1,20 @@
|
||||
module github.com/waste-go
|
||||
|
||||
go 1.24.0
|
||||
go 1.25.0
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.2.0
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/pion/webrtc/v3 v3.3.6
|
||||
golang.org/x/crypto v0.24.0
|
||||
nhooyr.io/websocket v1.8.17
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/ncruces/go-strftime v1.0.0 // indirect
|
||||
github.com/pion/datachannel v1.5.8 // indirect
|
||||
github.com/pion/dtls/v2 v2.2.12 // indirect
|
||||
github.com/pion/ice/v2 v2.3.38 // indirect
|
||||
@@ -26,11 +30,15 @@ require (
|
||||
github.com/pion/stun v0.6.1 // indirect
|
||||
github.com/pion/transport/v2 v2.2.10 // indirect
|
||||
github.com/pion/turn/v2 v2.1.6 // indirect
|
||||
github.com/pion/webrtc/v3 v3.3.6 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
github.com/wlynxg/anet v0.0.3 // indirect
|
||||
golang.org/x/net v0.22.0 // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
golang.org/x/sys v0.44.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
modernc.org/libc v1.73.4 // indirect
|
||||
modernc.org/mathutil v1.7.1 // indirect
|
||||
modernc.org/memory v1.11.0 // indirect
|
||||
modernc.org/sqlite v1.53.0 // indirect
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user