Key per-channel storage by PSK-derived channel ID
Channel messages, settings, region, order and images were persisted by radio slot index, so a slot reused for a different channel inherited the old channel's history and settings (#359). - Channel.storageId: first 8 bytes of SHA-256("meshcore-channel:" + psk). - All per-channel stores key by channel ID; in-memory state stays by slot. - The connector keeps a slot -> channel ID map, diffs it against the saved map on every channel sync and reloads slots whose channel changed. - Queued channel frames wait until this session's map is confirmed. - One-shot per-radio migration from slot keys, using the cached channel list the legacy data was written under; rerun-safe if interrupted. - Deleting a channel clears its data; a channel removed elsewhere keeps its history and gets it back when re-added. A PSK edit keeps its place in the custom order. - Slots sharing a PSK share history and settings. - Image entries record their channel ID; a slot change resets that slot's in-progress reassembly.
This commit is contained in:
1 parent
d30744aa31
commit
679116ed03
24 files changed
+1794
-340
No files matched your search
@@ -210,6 +210,54 @@ void main() {
|
||||
expect(h.decoder.calls, 1);
|
||||
});
|
||||
|
||||
test('a stream started before its slot had an ID picks one up', () async {
|
||||
final h = _build();
|
||||
final set = buildImageChunks(
|
||||
payload: _payload(kImageChunkFirstCapacity + kImageChunkCapacity + 1),
|
||||
metadata: const ImageStreamMetadata(rate: ImageCodecRatePoint.standard),
|
||||
senderPrefix: kSender,
|
||||
imgId: 5,
|
||||
);
|
||||
expect(set.dataChunkCount, 3);
|
||||
|
||||
final first = await h.store.handleOutcome(
|
||||
h.reassembler.addChunk(set.blobs[0], channelIndex: 3),
|
||||
channelIndex: 3,
|
||||
);
|
||||
expect(first!.channelId, isNull);
|
||||
// A second data chunk of three neither completes nor recovers it.
|
||||
final second = await h.store.handleOutcome(
|
||||
h.reassembler.addChunk(set.blobs[1], channelIndex: 3),
|
||||
channelIndex: 3,
|
||||
channelId: 'chan-id',
|
||||
);
|
||||
expect(second!.state, ReceivedImageState.receiving);
|
||||
expect(second.streamId, first.streamId);
|
||||
expect(second.channelId, 'chan-id');
|
||||
});
|
||||
|
||||
test('a stream completed after its slot got an ID keeps it', () async {
|
||||
final h = _build();
|
||||
final set = buildImageChunks(
|
||||
payload: _payload(kImageChunkFirstCapacity + 1),
|
||||
metadata: const ImageStreamMetadata(rate: ImageCodecRatePoint.standard),
|
||||
senderPrefix: kSender,
|
||||
imgId: 6,
|
||||
);
|
||||
final first = await h.store.handleOutcome(
|
||||
h.reassembler.addChunk(set.blobs[0], channelIndex: 3),
|
||||
channelIndex: 3,
|
||||
);
|
||||
expect(first!.channelId, isNull);
|
||||
final done = await h.store.handleOutcome(
|
||||
h.reassembler.addChunk(set.blobs[1], channelIndex: 3),
|
||||
channelIndex: 3,
|
||||
channelId: 'chan-id',
|
||||
);
|
||||
expect(done!.streamId, first.streamId);
|
||||
expect(done.channelId, 'chan-id');
|
||||
});
|
||||
|
||||
test('two-chunk image reports 1 of 2 while incomplete', () async {
|
||||
final h = _build();
|
||||
final set = buildImageChunks(
|
||||
@@ -962,7 +1010,7 @@ void main() {
|
||||
|
||||
group('deletion hooks', () {
|
||||
test(
|
||||
'deleteImagesForChannel reclaims every image of one conversation',
|
||||
'deleteImagesForChannelId reclaims every image of one conversation',
|
||||
() async {
|
||||
final h = _build();
|
||||
final a = await _completeOne(h, imgId: 130);
|
||||
@@ -972,6 +1020,7 @@ void main() {
|
||||
// A third image on another channel must survive.
|
||||
final other = await h.store.registerOutgoing(
|
||||
channelIndex: 9,
|
||||
channelId: 'fedcba9876543210',
|
||||
senderPrefix: kSelf,
|
||||
imgId: 5,
|
||||
previewPng: Uint8List.fromList(List<int>.filled(32, 2)),
|
||||
@@ -979,7 +1028,7 @@ void main() {
|
||||
chunkCount: 1,
|
||||
);
|
||||
|
||||
final removed = await h.store.deleteImagesForChannel(3);
|
||||
final removed = await h.store.deleteImagesForChannelId(_channel3Id);
|
||||
expect(removed, containsAll(<String>[a.streamId, b.streamId]));
|
||||
expect(h.store.entryFor(a.streamId), isNull);
|
||||
expect(h.store.entryFor(b.streamId), isNull);
|
||||
@@ -1480,7 +1529,10 @@ Future<ReceivedImageEntry> _completeOne(
|
||||
final entry = await h.store.handleOutcome(
|
||||
h.reassembler.addChunk(set.blobs[0], channelIndex: 3, now: h.clock()),
|
||||
channelIndex: 3,
|
||||
channelId: _channel3Id,
|
||||
at: h.clock(),
|
||||
);
|
||||
return entry!;
|
||||
}
|
||||
|
||||
const _channel3Id = '0123456789abcdef';
|
||||
Reference in new issue
Block a user