feat: EXT-007 P2P message history gossip
After hello verification, the connecting peer sends history_request to the first peer it meets (one per room, no fan-out). The responder queries SQLite and replies with a history_chunk. Received history is stored via INSERT OR IGNORE (mid dedup) and emitted as history_loaded IPC events. - proto: MsgHistoryRequest/Chunk types, HistoryEntry, EvtHistoryLoaded, ComputeMsgID (sha256 content-addressed ID), MsgID field on ChatMessage - store: ALTER TABLE ADD COLUMN msg_id + unique index migration (idempotent); RecentMessagesSince query (msg_id IS NOT NULL filter); msg_id persisted on save - mesh: RequestHistoryFrom, HandleHistoryRequest, HandleHistoryChunk methods; historyRequested/historyFirstPeer state to ensure single-peer requests - peer: dispatch history_request/history_chunk; RequestHistoryFrom after hello; stamp MsgID on incoming chat messages - ipc: stamp MsgID on outgoing group chat messages - EXTENSIONS.md: EXT-007 documented Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -197,6 +197,8 @@ func handleDCMessage(data []byte, from proto.PeerID, localID *crypto.Identity, m
|
||||
})
|
||||
// Tell the new peer about everyone we can currently see.
|
||||
go m.sendGossipTo(from)
|
||||
// Request message history from this peer (EXT-007).
|
||||
go m.RequestHistoryFrom(from)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -212,11 +214,12 @@ func dispatchPeerMessage(msg proto.PeerMessage, from proto.PeerID, m *Mesh) {
|
||||
switch msg.Type {
|
||||
case proto.MsgChat:
|
||||
chat := &proto.ChatMessage{
|
||||
Mid: midOrRandom(msg.Mid),
|
||||
From: from,
|
||||
Room: msg.Room,
|
||||
Text: msg.Text,
|
||||
Ts: msg.Ts,
|
||||
Mid: midOrRandom(msg.Mid),
|
||||
MsgID: proto.ComputeMsgID(from, msg.Room, msg.Ts, msg.Text),
|
||||
From: from,
|
||||
Room: msg.Room,
|
||||
Text: msg.Text,
|
||||
Ts: msg.Ts,
|
||||
}
|
||||
m.SaveMessage(chat)
|
||||
m.Emit(proto.IpcMessage{Type: proto.EvtMessageReceived, Message: chat})
|
||||
@@ -298,6 +301,12 @@ func dispatchPeerMessage(msg proto.PeerMessage, from proto.PeerID, m *Mesh) {
|
||||
}
|
||||
}
|
||||
log.Printf("mesh: gossip from %s: %d hints, %d new", from.Short(), len(msg.Gossip.Peers), newPeers)
|
||||
case proto.MsgHistoryRequest:
|
||||
go m.HandleHistoryRequest(from, msg.Room, msg.Since, msg.Limit)
|
||||
|
||||
case proto.MsgHistoryChunk:
|
||||
go m.HandleHistoryChunk(msg.Room, msg.History)
|
||||
|
||||
case proto.MsgPing:
|
||||
log.Printf("mesh: ping from %s", from.Short())
|
||||
case proto.MsgPong:
|
||||
|
||||
Reference in New Issue
Block a user