mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-10-11 12:48:34 -04:00
update for api fixes
This commit is contained in:
parent
a1a6872e3f
commit
7a1fa6dfb8
5 changed files with 42 additions and 13 deletions
|
@ -226,7 +226,7 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
Future<Uint8List?> tryWriteBytes(Uint8List newValue,
|
||||
{int subkey = -1,
|
||||
VeilidCrypto? crypto,
|
||||
KeyPair? writer,
|
||||
SetDHTValueOptions? options,
|
||||
Output<int>? outSeqNum}) =>
|
||||
_wrapStats('tryWriteBytes', () async {
|
||||
subkey = subkeyOrDefault(subkey);
|
||||
|
@ -236,7 +236,9 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
// Set the new data if possible
|
||||
var newValueData = await _routingContext.setDHTValue(
|
||||
key, subkey, encryptedNewValue,
|
||||
writer: writer ?? _writer);
|
||||
options: SetDHTValueOptions(
|
||||
writer: options?.writer ?? _writer,
|
||||
allowOffline: options?.allowOffline));
|
||||
if (newValueData == null) {
|
||||
// A newer value wasn't found on the set, but we may get a newer value
|
||||
// when getting the value for the sequence number
|
||||
|
@ -292,7 +294,8 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
// Set the new data
|
||||
newValueData = await _routingContext.setDHTValue(
|
||||
key, subkey, encryptedNewValue,
|
||||
writer: writer ?? _writer);
|
||||
options: SetDHTValueOptions(
|
||||
writer: writer ?? _writer, allowOffline: false));
|
||||
|
||||
// Repeat if newer data on the network was found
|
||||
} while (newValueData != null);
|
||||
|
@ -351,7 +354,8 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
oldValue = await tryWriteBytes(updatedValue,
|
||||
subkey: subkey,
|
||||
crypto: crypto,
|
||||
writer: writer,
|
||||
options: SetDHTValueOptions(
|
||||
writer: writer ?? _writer, allowOffline: false),
|
||||
outSeqNum: outSeqNum);
|
||||
|
||||
// Repeat update if newer data on the network was found
|
||||
|
@ -362,12 +366,12 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
Future<T?> tryWriteJson<T>(T Function(dynamic) fromJson, T newValue,
|
||||
{int subkey = -1,
|
||||
VeilidCrypto? crypto,
|
||||
KeyPair? writer,
|
||||
SetDHTValueOptions? options,
|
||||
Output<int>? outSeqNum}) =>
|
||||
tryWriteBytes(jsonEncodeBytes(newValue),
|
||||
subkey: subkey,
|
||||
crypto: crypto,
|
||||
writer: writer,
|
||||
options: options,
|
||||
outSeqNum: outSeqNum)
|
||||
.then((out) {
|
||||
if (out == null) {
|
||||
|
@ -381,12 +385,12 @@ class DHTRecord implements DHTDeleteable<DHTRecord> {
|
|||
T Function(List<int>) fromBuffer, T newValue,
|
||||
{int subkey = -1,
|
||||
VeilidCrypto? crypto,
|
||||
KeyPair? writer,
|
||||
SetDHTValueOptions? options,
|
||||
Output<int>? outSeqNum}) =>
|
||||
tryWriteBytes(newValue.writeToBuffer(),
|
||||
subkey: subkey,
|
||||
crypto: crypto,
|
||||
writer: writer,
|
||||
options: options,
|
||||
outSeqNum: outSeqNum)
|
||||
.then((out) {
|
||||
if (out == null) {
|
||||
|
|
|
@ -98,18 +98,20 @@ sealed class SuperIdentity with _$SuperIdentity {
|
|||
}
|
||||
|
||||
/// Opens an existing super identity, validates it, and returns it
|
||||
static Future<SuperIdentity> open({required TypedKey superRecordKey}) async {
|
||||
static Future<SuperIdentity?> open({required TypedKey superRecordKey}) async {
|
||||
final pool = DHTRecordPool.instance;
|
||||
|
||||
// SuperIdentity DHT record is public/unencrypted
|
||||
return (await pool.openRecordRead(superRecordKey,
|
||||
debugName: 'SuperIdentity::openSuperIdentity::SuperIdentityRecord'))
|
||||
.deleteScope((superRec) async {
|
||||
final superIdentity = (await superRec.getJson(SuperIdentity.fromJson,
|
||||
refreshMode: DHTRecordRefreshMode.network))!;
|
||||
final superIdentity = await superRec.getJson(SuperIdentity.fromJson,
|
||||
refreshMode: DHTRecordRefreshMode.network);
|
||||
if (superIdentity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
await superIdentity.validate(superRecordKey: superRecordKey);
|
||||
|
||||
return superIdentity;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue