feat(useragent): initial connection impl
This commit is contained in:
22
useragent/lib/providers/connection/bootstrap_token.dart
Normal file
22
useragent/lib/providers/connection/bootstrap_token.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'bootstrap_token.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class BootstrapToken extends _$BootstrapToken {
|
||||
String? build() {
|
||||
return null;
|
||||
}
|
||||
|
||||
void set(String token) {
|
||||
state = token;
|
||||
}
|
||||
|
||||
String? take() {
|
||||
final token = state;
|
||||
state = null;
|
||||
return token;
|
||||
}
|
||||
}
|
||||
62
useragent/lib/providers/connection/bootstrap_token.g.dart
Normal file
62
useragent/lib/providers/connection/bootstrap_token.g.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'bootstrap_token.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(BootstrapToken)
|
||||
final bootstrapTokenProvider = BootstrapTokenProvider._();
|
||||
|
||||
final class BootstrapTokenProvider
|
||||
extends $NotifierProvider<BootstrapToken, String?> {
|
||||
BootstrapTokenProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'bootstrapTokenProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$bootstrapTokenHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
BootstrapToken create() => BootstrapToken();
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(String? value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<String?>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$bootstrapTokenHash() => r'a59e679ab0561ed2ab4148660499891571d439db';
|
||||
|
||||
abstract class _$BootstrapToken extends $Notifier<String?> {
|
||||
String? build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<String?, String?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<String?, String?>,
|
||||
String?,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
39
useragent/lib/providers/connection/connection_manager.dart
Normal file
39
useragent/lib/providers/connection/connection_manager.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:arbiter/features/connection/connection.dart';
|
||||
import 'package:arbiter/providers/connection/bootstrap_token.dart';
|
||||
import 'package:arbiter/providers/key.dart';
|
||||
import 'package:arbiter/providers/server_info.dart';
|
||||
import 'package:mtcore/markettakers.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'connection_manager.g.dart';
|
||||
|
||||
@Riverpod(keepAlive: true)
|
||||
class ConnectionManager extends _$ConnectionManager {
|
||||
@override
|
||||
Future<Connection?> build() async {
|
||||
final serverInfo = await ref.watch(serverInfoProvider.future);
|
||||
final key = await ref.watch(keyProvider.future);
|
||||
final token = ref.watch(bootstrapTokenProvider);
|
||||
|
||||
if (serverInfo == null || key == null) {
|
||||
return null;
|
||||
}
|
||||
final Connection connection;
|
||||
try {
|
||||
connection = await connectAndAuthorize(serverInfo, key, bootstrapToken: token);
|
||||
} catch (e) {
|
||||
talker.handle(e);
|
||||
rethrow;
|
||||
}
|
||||
|
||||
|
||||
ref.onDispose(() {
|
||||
final connection = state.asData?.value;
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
});
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
54
useragent/lib/providers/connection/connection_manager.g.dart
Normal file
54
useragent/lib/providers/connection/connection_manager.g.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'connection_manager.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
|
||||
@ProviderFor(ConnectionManager)
|
||||
final connectionManagerProvider = ConnectionManagerProvider._();
|
||||
|
||||
final class ConnectionManagerProvider
|
||||
extends $AsyncNotifierProvider<ConnectionManager, Connection?> {
|
||||
ConnectionManagerProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'connectionManagerProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$connectionManagerHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
ConnectionManager create() => ConnectionManager();
|
||||
}
|
||||
|
||||
String _$connectionManagerHash() => r'8923346dff75a9a06127c71a0a39ca65d9733d8c';
|
||||
|
||||
abstract class _$ConnectionManager extends $AsyncNotifier<Connection?> {
|
||||
FutureOr<Connection?> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final ref = this.ref as $Ref<AsyncValue<Connection?>, Connection?>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<Connection?>, Connection?>,
|
||||
AsyncValue<Connection?>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleCreate(ref, build);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:mtcore/markettakers.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:arbiter/features/pk_manager.dart';
|
||||
import 'package:arbiter/features/simple_ed25519.dart';
|
||||
import 'package:arbiter/features/identity/pk_manager.dart';
|
||||
import 'package:arbiter/features/identity/simple_ed25519.dart';
|
||||
|
||||
part 'key.g.dart';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:arbiter/features/server_info_storage.dart';
|
||||
import 'package:arbiter/features/connection/server_info_storage.dart';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user