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