mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-10-01 06:55:46 -04:00
parent fix
This commit is contained in:
parent
4a554841d1
commit
bbe2d60c7f
@ -70,7 +70,6 @@ Future<AcceptedOrRejectedContact?> checkAcceptRejectContact(
|
|||||||
final signedContactResponse = await contactRequestInbox
|
final signedContactResponse = await contactRequestInbox
|
||||||
.getProtobuf(SignedContactResponse.fromBuffer, forceRefresh: true);
|
.getProtobuf(SignedContactResponse.fromBuffer, forceRefresh: true);
|
||||||
if (signedContactResponse == null) {
|
if (signedContactResponse == null) {
|
||||||
log.error('failed to get signed contact response');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ class DHTRecordPoolAllocations with _$DHTRecordPoolAllocations {
|
|||||||
childrenByParent, // String key due to IMap<> json unsupported in key
|
childrenByParent, // String key due to IMap<> json unsupported in key
|
||||||
required IMap<String, TypedKey>
|
required IMap<String, TypedKey>
|
||||||
parentByChild, // String key due to IMap<> json unsupported in key
|
parentByChild, // String key due to IMap<> json unsupported in key
|
||||||
|
required ISet<TypedKey> rootRecords,
|
||||||
}) = _DHTRecordPoolAllocations;
|
}) = _DHTRecordPoolAllocations;
|
||||||
|
|
||||||
factory DHTRecordPoolAllocations.fromJson(dynamic json) =>
|
factory DHTRecordPoolAllocations.fromJson(dynamic json) =>
|
||||||
@ -38,7 +39,9 @@ class OwnedDHTRecordPointer with _$OwnedDHTRecordPointer {
|
|||||||
class DHTRecordPool with AsyncTableDBBacked<DHTRecordPoolAllocations> {
|
class DHTRecordPool with AsyncTableDBBacked<DHTRecordPoolAllocations> {
|
||||||
DHTRecordPool._(Veilid veilid, VeilidRoutingContext routingContext)
|
DHTRecordPool._(Veilid veilid, VeilidRoutingContext routingContext)
|
||||||
: _state = DHTRecordPoolAllocations(
|
: _state = DHTRecordPoolAllocations(
|
||||||
childrenByParent: IMap(), parentByChild: IMap()),
|
childrenByParent: IMap(),
|
||||||
|
parentByChild: IMap(),
|
||||||
|
rootRecords: ISet()),
|
||||||
_opened = <TypedKey, Mutex>{},
|
_opened = <TypedKey, Mutex>{},
|
||||||
_routingContext = routingContext,
|
_routingContext = routingContext,
|
||||||
_veilid = veilid;
|
_veilid = veilid;
|
||||||
@ -64,7 +67,7 @@ class DHTRecordPool with AsyncTableDBBacked<DHTRecordPoolAllocations> {
|
|||||||
DHTRecordPoolAllocations valueFromJson(Object? obj) => obj != null
|
DHTRecordPoolAllocations valueFromJson(Object? obj) => obj != null
|
||||||
? DHTRecordPoolAllocations.fromJson(obj)
|
? DHTRecordPoolAllocations.fromJson(obj)
|
||||||
: DHTRecordPoolAllocations(
|
: DHTRecordPoolAllocations(
|
||||||
childrenByParent: IMap(), parentByChild: IMap());
|
childrenByParent: IMap(), parentByChild: IMap(), rootRecords: ISet());
|
||||||
@override
|
@override
|
||||||
Object? valueToJson(DHTRecordPoolAllocations val) => val.toJson();
|
Object? valueToJson(DHTRecordPoolAllocations val) => val.toJson();
|
||||||
|
|
||||||
@ -133,13 +136,32 @@ class DHTRecordPool with AsyncTableDBBacked<DHTRecordPoolAllocations> {
|
|||||||
await Future.wait(allFutures);
|
await Future.wait(allFutures);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _addDependency(TypedKey parent, TypedKey child) async {
|
Future<void> _addDependency(TypedKey? parent, TypedKey child) async {
|
||||||
|
if (parent == null) {
|
||||||
|
if (_state.rootRecords.contains(child)) {
|
||||||
|
// Dependency already added
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_state.parentByChild.containsKey(child.toJson())) {
|
||||||
|
throw StateError('Child is already parented: $child');
|
||||||
|
}
|
||||||
|
if (_state.childrenByParent.containsKey(child.toJson())) {
|
||||||
|
// dependencies should be opened after their parents
|
||||||
|
throw StateError('Child is not a leaf: $child');
|
||||||
|
}
|
||||||
|
|
||||||
|
_state = await store(
|
||||||
|
_state.copyWith(rootRecords: _state.rootRecords.add(child)));
|
||||||
|
} else {
|
||||||
final childrenOfParent =
|
final childrenOfParent =
|
||||||
_state.childrenByParent[parent.toJson()] ?? ISet<TypedKey>();
|
_state.childrenByParent[parent.toJson()] ?? ISet<TypedKey>();
|
||||||
if (childrenOfParent.contains(child)) {
|
if (childrenOfParent.contains(child)) {
|
||||||
// Dependency already added (consecutive opens, etc)
|
// Dependency already added (consecutive opens, etc)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (_state.rootRecords.contains(child)) {
|
||||||
|
throw StateError('Child already added as root: $child');
|
||||||
|
}
|
||||||
if (_state.parentByChild.containsKey(child.toJson())) {
|
if (_state.parentByChild.containsKey(child.toJson())) {
|
||||||
throw StateError('Child has two parents: $child <- $parent');
|
throw StateError('Child has two parents: $child <- $parent');
|
||||||
}
|
}
|
||||||
@ -153,8 +175,13 @@ class DHTRecordPool with AsyncTableDBBacked<DHTRecordPoolAllocations> {
|
|||||||
.add(parent.toJson(), childrenOfParent.add(child)),
|
.add(parent.toJson(), childrenOfParent.add(child)),
|
||||||
parentByChild: _state.parentByChild.add(child.toJson(), parent)));
|
parentByChild: _state.parentByChild.add(child.toJson(), parent)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _removeDependency(TypedKey child) async {
|
Future<void> _removeDependency(TypedKey child) async {
|
||||||
|
if (_state.rootRecords.contains(child)) {
|
||||||
|
_state = await store(
|
||||||
|
_state.copyWith(rootRecords: _state.rootRecords.remove(child)));
|
||||||
|
} else {
|
||||||
final parent = _state.parentByChild[child.toJson()];
|
final parent = _state.parentByChild[child.toJson()];
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
return;
|
return;
|
||||||
@ -173,6 +200,7 @@ class DHTRecordPool with AsyncTableDBBacked<DHTRecordPoolAllocations> {
|
|||||||
}
|
}
|
||||||
_state = await store(newState);
|
_state = await store(newState);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ mixin _$DHTRecordPoolAllocations {
|
|||||||
IMap<String, ISet<Typed<FixedEncodedString43>>> get childrenByParent =>
|
IMap<String, ISet<Typed<FixedEncodedString43>>> get childrenByParent =>
|
||||||
throw _privateConstructorUsedError; // String key due to IMap<> json unsupported in key
|
throw _privateConstructorUsedError; // String key due to IMap<> json unsupported in key
|
||||||
IMap<String, Typed<FixedEncodedString43>> get parentByChild =>
|
IMap<String, Typed<FixedEncodedString43>> get parentByChild =>
|
||||||
|
throw _privateConstructorUsedError; // String key due to IMap<> json unsupported in key
|
||||||
|
ISet<Typed<FixedEncodedString43>> get rootRecords =>
|
||||||
throw _privateConstructorUsedError;
|
throw _privateConstructorUsedError;
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||||
@ -40,7 +42,8 @@ abstract class $DHTRecordPoolAllocationsCopyWith<$Res> {
|
|||||||
@useResult
|
@useResult
|
||||||
$Res call(
|
$Res call(
|
||||||
{IMap<String, ISet<Typed<FixedEncodedString43>>> childrenByParent,
|
{IMap<String, ISet<Typed<FixedEncodedString43>>> childrenByParent,
|
||||||
IMap<String, Typed<FixedEncodedString43>> parentByChild});
|
IMap<String, Typed<FixedEncodedString43>> parentByChild,
|
||||||
|
ISet<Typed<FixedEncodedString43>> rootRecords});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@ -59,6 +62,7 @@ class _$DHTRecordPoolAllocationsCopyWithImpl<$Res,
|
|||||||
$Res call({
|
$Res call({
|
||||||
Object? childrenByParent = null,
|
Object? childrenByParent = null,
|
||||||
Object? parentByChild = null,
|
Object? parentByChild = null,
|
||||||
|
Object? rootRecords = null,
|
||||||
}) {
|
}) {
|
||||||
return _then(_value.copyWith(
|
return _then(_value.copyWith(
|
||||||
childrenByParent: null == childrenByParent
|
childrenByParent: null == childrenByParent
|
||||||
@ -69,6 +73,10 @@ class _$DHTRecordPoolAllocationsCopyWithImpl<$Res,
|
|||||||
? _value.parentByChild
|
? _value.parentByChild
|
||||||
: parentByChild // ignore: cast_nullable_to_non_nullable
|
: parentByChild // ignore: cast_nullable_to_non_nullable
|
||||||
as IMap<String, Typed<FixedEncodedString43>>,
|
as IMap<String, Typed<FixedEncodedString43>>,
|
||||||
|
rootRecords: null == rootRecords
|
||||||
|
? _value.rootRecords
|
||||||
|
: rootRecords // ignore: cast_nullable_to_non_nullable
|
||||||
|
as ISet<Typed<FixedEncodedString43>>,
|
||||||
) as $Val);
|
) as $Val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +92,8 @@ abstract class _$$_DHTRecordPoolAllocationsCopyWith<$Res>
|
|||||||
@useResult
|
@useResult
|
||||||
$Res call(
|
$Res call(
|
||||||
{IMap<String, ISet<Typed<FixedEncodedString43>>> childrenByParent,
|
{IMap<String, ISet<Typed<FixedEncodedString43>>> childrenByParent,
|
||||||
IMap<String, Typed<FixedEncodedString43>> parentByChild});
|
IMap<String, Typed<FixedEncodedString43>> parentByChild,
|
||||||
|
ISet<Typed<FixedEncodedString43>> rootRecords});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @nodoc
|
/// @nodoc
|
||||||
@ -101,6 +110,7 @@ class __$$_DHTRecordPoolAllocationsCopyWithImpl<$Res>
|
|||||||
$Res call({
|
$Res call({
|
||||||
Object? childrenByParent = null,
|
Object? childrenByParent = null,
|
||||||
Object? parentByChild = null,
|
Object? parentByChild = null,
|
||||||
|
Object? rootRecords = null,
|
||||||
}) {
|
}) {
|
||||||
return _then(_$_DHTRecordPoolAllocations(
|
return _then(_$_DHTRecordPoolAllocations(
|
||||||
childrenByParent: null == childrenByParent
|
childrenByParent: null == childrenByParent
|
||||||
@ -111,6 +121,10 @@ class __$$_DHTRecordPoolAllocationsCopyWithImpl<$Res>
|
|||||||
? _value.parentByChild
|
? _value.parentByChild
|
||||||
: parentByChild // ignore: cast_nullable_to_non_nullable
|
: parentByChild // ignore: cast_nullable_to_non_nullable
|
||||||
as IMap<String, Typed<FixedEncodedString43>>,
|
as IMap<String, Typed<FixedEncodedString43>>,
|
||||||
|
rootRecords: null == rootRecords
|
||||||
|
? _value.rootRecords
|
||||||
|
: rootRecords // ignore: cast_nullable_to_non_nullable
|
||||||
|
as ISet<Typed<FixedEncodedString43>>,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +133,9 @@ class __$$_DHTRecordPoolAllocationsCopyWithImpl<$Res>
|
|||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class _$_DHTRecordPoolAllocations implements _DHTRecordPoolAllocations {
|
class _$_DHTRecordPoolAllocations implements _DHTRecordPoolAllocations {
|
||||||
const _$_DHTRecordPoolAllocations(
|
const _$_DHTRecordPoolAllocations(
|
||||||
{required this.childrenByParent, required this.parentByChild});
|
{required this.childrenByParent,
|
||||||
|
required this.parentByChild,
|
||||||
|
required this.rootRecords});
|
||||||
|
|
||||||
factory _$_DHTRecordPoolAllocations.fromJson(Map<String, dynamic> json) =>
|
factory _$_DHTRecordPoolAllocations.fromJson(Map<String, dynamic> json) =>
|
||||||
_$$_DHTRecordPoolAllocationsFromJson(json);
|
_$$_DHTRecordPoolAllocationsFromJson(json);
|
||||||
@ -129,10 +145,13 @@ class _$_DHTRecordPoolAllocations implements _DHTRecordPoolAllocations {
|
|||||||
// String key due to IMap<> json unsupported in key
|
// String key due to IMap<> json unsupported in key
|
||||||
@override
|
@override
|
||||||
final IMap<String, Typed<FixedEncodedString43>> parentByChild;
|
final IMap<String, Typed<FixedEncodedString43>> parentByChild;
|
||||||
|
// String key due to IMap<> json unsupported in key
|
||||||
|
@override
|
||||||
|
final ISet<Typed<FixedEncodedString43>> rootRecords;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'DHTRecordPoolAllocations(childrenByParent: $childrenByParent, parentByChild: $parentByChild)';
|
return 'DHTRecordPoolAllocations(childrenByParent: $childrenByParent, parentByChild: $parentByChild, rootRecords: $rootRecords)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -143,12 +162,15 @@ class _$_DHTRecordPoolAllocations implements _DHTRecordPoolAllocations {
|
|||||||
(identical(other.childrenByParent, childrenByParent) ||
|
(identical(other.childrenByParent, childrenByParent) ||
|
||||||
other.childrenByParent == childrenByParent) &&
|
other.childrenByParent == childrenByParent) &&
|
||||||
(identical(other.parentByChild, parentByChild) ||
|
(identical(other.parentByChild, parentByChild) ||
|
||||||
other.parentByChild == parentByChild));
|
other.parentByChild == parentByChild) &&
|
||||||
|
const DeepCollectionEquality()
|
||||||
|
.equals(other.rootRecords, rootRecords));
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
@override
|
@override
|
||||||
int get hashCode => Object.hash(runtimeType, childrenByParent, parentByChild);
|
int get hashCode => Object.hash(runtimeType, childrenByParent, parentByChild,
|
||||||
|
const DeepCollectionEquality().hash(rootRecords));
|
||||||
|
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
@override
|
@override
|
||||||
@ -169,8 +191,9 @@ abstract class _DHTRecordPoolAllocations implements DHTRecordPoolAllocations {
|
|||||||
const factory _DHTRecordPoolAllocations(
|
const factory _DHTRecordPoolAllocations(
|
||||||
{required final IMap<String, ISet<Typed<FixedEncodedString43>>>
|
{required final IMap<String, ISet<Typed<FixedEncodedString43>>>
|
||||||
childrenByParent,
|
childrenByParent,
|
||||||
required final IMap<String, Typed<FixedEncodedString43>>
|
required final IMap<String, Typed<FixedEncodedString43>> parentByChild,
|
||||||
parentByChild}) = _$_DHTRecordPoolAllocations;
|
required final ISet<Typed<FixedEncodedString43>>
|
||||||
|
rootRecords}) = _$_DHTRecordPoolAllocations;
|
||||||
|
|
||||||
factory _DHTRecordPoolAllocations.fromJson(Map<String, dynamic> json) =
|
factory _DHTRecordPoolAllocations.fromJson(Map<String, dynamic> json) =
|
||||||
_$_DHTRecordPoolAllocations.fromJson;
|
_$_DHTRecordPoolAllocations.fromJson;
|
||||||
@ -179,6 +202,8 @@ abstract class _DHTRecordPoolAllocations implements DHTRecordPoolAllocations {
|
|||||||
IMap<String, ISet<Typed<FixedEncodedString43>>> get childrenByParent;
|
IMap<String, ISet<Typed<FixedEncodedString43>>> get childrenByParent;
|
||||||
@override // String key due to IMap<> json unsupported in key
|
@override // String key due to IMap<> json unsupported in key
|
||||||
IMap<String, Typed<FixedEncodedString43>> get parentByChild;
|
IMap<String, Typed<FixedEncodedString43>> get parentByChild;
|
||||||
|
@override // String key due to IMap<> json unsupported in key
|
||||||
|
ISet<Typed<FixedEncodedString43>> get rootRecords;
|
||||||
@override
|
@override
|
||||||
@JsonKey(ignore: true)
|
@JsonKey(ignore: true)
|
||||||
_$$_DHTRecordPoolAllocationsCopyWith<_$_DHTRecordPoolAllocations>
|
_$$_DHTRecordPoolAllocationsCopyWith<_$_DHTRecordPoolAllocations>
|
||||||
|
@ -19,6 +19,9 @@ _$_DHTRecordPoolAllocations _$$_DHTRecordPoolAllocationsFromJson(
|
|||||||
json['parent_by_child'] as Map<String, dynamic>,
|
json['parent_by_child'] as Map<String, dynamic>,
|
||||||
(value) => value as String,
|
(value) => value as String,
|
||||||
(value) => Typed<FixedEncodedString43>.fromJson(value)),
|
(value) => Typed<FixedEncodedString43>.fromJson(value)),
|
||||||
|
rootRecords: ISet<Typed<FixedEncodedString43>>.fromJson(
|
||||||
|
json['root_records'],
|
||||||
|
(value) => Typed<FixedEncodedString43>.fromJson(value)),
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$$_DHTRecordPoolAllocationsToJson(
|
Map<String, dynamic> _$$_DHTRecordPoolAllocationsToJson(
|
||||||
@ -34,6 +37,9 @@ Map<String, dynamic> _$$_DHTRecordPoolAllocationsToJson(
|
|||||||
(value) => value,
|
(value) => value,
|
||||||
(value) => value.toJson(),
|
(value) => value.toJson(),
|
||||||
),
|
),
|
||||||
|
'root_records': instance.rootRecords.toJson(
|
||||||
|
(value) => value.toJson(),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
_$_OwnedDHTRecordPointer _$$_OwnedDHTRecordPointerFromJson(
|
_$_OwnedDHTRecordPointer _$$_OwnedDHTRecordPointerFromJson(
|
||||||
|
Loading…
Reference in New Issue
Block a user