mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-08-07 13:42:16 -04:00
remove swap from dhtlog
This commit is contained in:
parent
d1559c949d
commit
b192c44d5c
5 changed files with 7 additions and 59 deletions
|
@ -47,6 +47,11 @@ class MessageIntegrity {
|
||||||
message.signature = signature.toProto();
|
message.signature = signature.toProto();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: change bool to an enum to allow for reconciling deleted
|
||||||
|
// XXX: messages. if a message is deleted it will not verify, but its
|
||||||
|
// XXX: signature will still be in place for the message chain.
|
||||||
|
// XXX: it should be added to a list to check for a ControlDelete that
|
||||||
|
// XXX: appears later in the message log.
|
||||||
Future<bool> verifyMessage(proto.Message message) {
|
Future<bool> verifyMessage(proto.Message message) {
|
||||||
// Ensure the message is signed
|
// Ensure the message is signed
|
||||||
assert(message.hasSignature(), 'should not verify unsigned message');
|
assert(message.hasSignature(), 'should not verify unsigned message');
|
||||||
|
|
|
@ -36,60 +36,6 @@ class _DHTLogWrite extends _DHTLogRead implements DHTLogWriteOperations {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> swap(int aPos, int bPos) async {
|
|
||||||
if (aPos < 0 || aPos >= _spine.length) {
|
|
||||||
throw IndexError.withLength(aPos, _spine.length);
|
|
||||||
}
|
|
||||||
if (bPos < 0 || bPos >= _spine.length) {
|
|
||||||
throw IndexError.withLength(bPos, _spine.length);
|
|
||||||
}
|
|
||||||
final aLookup = await _spine.lookupPosition(aPos);
|
|
||||||
if (aLookup == null) {
|
|
||||||
throw DHTExceptionInvalidData('_DHTLogWrite::swap aPos=$aPos bPos=$bPos '
|
|
||||||
'_spine.length=${_spine.length}');
|
|
||||||
}
|
|
||||||
final bLookup = await _spine.lookupPosition(bPos);
|
|
||||||
if (bLookup == null) {
|
|
||||||
await aLookup.close();
|
|
||||||
throw DHTExceptionInvalidData('_DHTLogWrite::swap aPos=$aPos bPos=$bPos '
|
|
||||||
'_spine.length=${_spine.length}');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Swap items in the segments
|
|
||||||
if (aLookup.shortArray == bLookup.shortArray) {
|
|
||||||
await bLookup.close();
|
|
||||||
return aLookup.scope((sa) => sa.operateWriteEventual(
|
|
||||||
(aWrite) => aWrite.swap(aLookup.pos, bLookup.pos)));
|
|
||||||
} else {
|
|
||||||
final bItem = Output<Uint8List>();
|
|
||||||
return aLookup.scope(
|
|
||||||
(sa) => bLookup.scope((sb) => sa.operateWriteEventual((aWrite) async {
|
|
||||||
if (bItem.value == null) {
|
|
||||||
final aItem = await aWrite.get(aLookup.pos);
|
|
||||||
if (aItem == null) {
|
|
||||||
throw DHTExceptionInvalidData(
|
|
||||||
'_DHTLogWrite::swap aPos=$aPos bPos=$bPos '
|
|
||||||
'aLookup.pos=${aLookup.pos} bLookup.pos=${bLookup.pos} '
|
|
||||||
'_spine.length=${_spine.length}');
|
|
||||||
}
|
|
||||||
await sb.operateWriteEventual((bWrite) async {
|
|
||||||
final success = await bWrite
|
|
||||||
.tryWriteItem(bLookup.pos, aItem, output: bItem);
|
|
||||||
if (!success) {
|
|
||||||
throw const DHTExceptionOutdated();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
final success =
|
|
||||||
await aWrite.tryWriteItem(aLookup.pos, bItem.value!);
|
|
||||||
if (!success) {
|
|
||||||
throw const DHTExceptionOutdated();
|
|
||||||
}
|
|
||||||
})));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> add(Uint8List value) async {
|
Future<void> add(Uint8List value) async {
|
||||||
// Allocate empty index at the end of the list
|
// Allocate empty index at the end of the list
|
||||||
|
|
|
@ -6,6 +6,7 @@ part of 'dht_short_array.dart';
|
||||||
abstract class DHTShortArrayWriteOperations
|
abstract class DHTShortArrayWriteOperations
|
||||||
implements
|
implements
|
||||||
DHTRandomRead,
|
DHTRandomRead,
|
||||||
|
DHTRandomSwap,
|
||||||
DHTRandomWrite,
|
DHTRandomWrite,
|
||||||
DHTInsertRemove,
|
DHTInsertRemove,
|
||||||
DHTAdd,
|
DHTAdd,
|
||||||
|
|
|
@ -23,11 +23,6 @@ abstract class DHTRandomWrite {
|
||||||
/// of the container.
|
/// of the container.
|
||||||
Future<bool> tryWriteItem(int pos, Uint8List newValue,
|
Future<bool> tryWriteItem(int pos, Uint8List newValue,
|
||||||
{Output<Uint8List>? output});
|
{Output<Uint8List>? output});
|
||||||
|
|
||||||
/// Swap items at position 'aPos' and 'bPos' in the DHTArray.
|
|
||||||
/// Throws an IndexError if either of the positions swapped exceeds the length
|
|
||||||
/// of the container
|
|
||||||
Future<void> swap(int aPos, int bPos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension DHTRandomWriteExt on DHTRandomWrite {
|
extension DHTRandomWriteExt on DHTRandomWrite {
|
||||||
|
|
|
@ -3,6 +3,7 @@ export 'dht_clear.dart';
|
||||||
export 'dht_closeable.dart';
|
export 'dht_closeable.dart';
|
||||||
export 'dht_insert_remove.dart';
|
export 'dht_insert_remove.dart';
|
||||||
export 'dht_random_read.dart';
|
export 'dht_random_read.dart';
|
||||||
|
export 'dht_random_swap.dart';
|
||||||
export 'dht_random_write.dart';
|
export 'dht_random_write.dart';
|
||||||
export 'dht_truncate.dart';
|
export 'dht_truncate.dart';
|
||||||
export 'exceptions.dart';
|
export 'exceptions.dart';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue