dht data structures

This commit is contained in:
Christien Rioux 2023-07-07 10:55:09 -04:00
parent 44a2761f87
commit dc59703f41
2 changed files with 45 additions and 13 deletions

28
lib/entities/dht.dart Normal file
View File

@ -0,0 +1,28 @@
import 'dart:typed_data';
import 'package:change_case/change_case.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:uuid/uuid.dart';
import 'package:veilid/veilid.dart';
part 'dht.freezed.dart';
part 'dht.g.dart';
// Header in subkey 0 for Fixed DHT Data
// Subkeys 1..=stride on the first key are concatenated chunks
// Subkeys 0..stride on the 'keys' keys are concatenated chunks
@freezed
class DHTData with _$DHTData {
const factory DHTData({
// Other keys to concatenate
required List<TypedKey> keys,
// Total data size
required int size,
// Chunk size per subkey
required int chunk,
// Subkeys per key
required int stride,
}) = _DHTData;
factory DHTData.fromJson(Map<String, dynamic> json) => _$DHTData(json);
}

View File

@ -27,8 +27,8 @@ class Messages with _$Messages {
}
// A record of a 1-1 chat that is synchronized between
// two users. Backed up on a DHT key.
//
// two users. Backed up on a DHT key. Visible and encrypted
// for the other party
//
// DHT Key (UnicastOutbox): conversationPublicKey
// DHT Secret: conversationSecret
@ -53,11 +53,16 @@ class Conversation with _$Conversation {
// Contains
@freezed
class Contact with _$Contact {
const factory Contact(
{required Profile remoteProfile,
const factory Contact({
// Profile as locally edited
required Profile localProfile,
// Profile from remote conversation
required Profile remoteProfile,
// Identity from remote conversation
required Identity identity,
required bool available}) = _Contact;
// xxx
required bool available,
}) = _Contact;
factory Contact.fromJson(Map<String, dynamic> json) =>
_$ContactFromJson(json);
@ -80,13 +85,15 @@ class Profile with _$Profile {
required String title,
// Status/away message
required String status,
// Icon data (png 128x128x24bit)
required Uint8List icon,
// Icon DHTData
required TypedKey icon,
}) = _Profile;
factory Profile.fromJson(Map<String, dynamic> json) =>
_$ProfileFromJson(json);
}
// A linked list of DHT subvalues
// A record of an individual account
// DHT Key (Private): accountPublicKey
// DHT Secret: accountSecretKey
@ -100,10 +107,7 @@ class Account with _$Account {
// Auto-away sets 'away' mode after an inactivity time
required autoAwayTimeoutSec,
// The contacts for this account
required List<Contact>,
xxx investigate immutable FIC lists and their use with freezed/jsonserializable, switch them here
required DHTListRef<Contact> contacts,
}) = _Account;
factory Account.fromJson(Map<String, dynamic> json) =>