Skip to content
Snippets Groups Projects
node.dart 2.59 KiB
Newer Older
vjrj's avatar
vjrj committed
import 'package:equatable/equatable.dart';
vjrj's avatar
vjrj committed
import 'package:flutter_dotenv/flutter_dotenv.dart';
vjrj's avatar
vjrj committed
import 'package:json_annotation/json_annotation.dart';

vjrj's avatar
vjrj committed
import 'is_json_serializable.dart';
vjrj's avatar
vjrj committed

vjrj's avatar
vjrj committed
part 'node.g.dart';

@JsonSerializable()
vjrj's avatar
vjrj committed
class Node extends Equatable implements IsJsonSerializable<Node> {
  const Node(
      {required this.url,
      this.latency = 99999,
      this.errors = 0,
      this.currentBlock = 0});
vjrj's avatar
vjrj committed

  factory Node.fromJson(Map<String, dynamic> json) => _$NodeFromJson(json);
vjrj's avatar
vjrj committed

vjrj's avatar
vjrj committed
  final String url;
  final int latency;
  final int errors;
  final int currentBlock;
vjrj's avatar
vjrj committed

  Node copyWith({String? url, int? latency, int? errors, int? currentBlock}) {
vjrj's avatar
vjrj committed
    return Node(
      url: url ?? this.url,
      latency: latency ?? this.latency,
      errors: errors ?? this.errors,
      currentBlock: currentBlock ?? this.currentBlock,
vjrj's avatar
vjrj committed
    );
  }

  @override
  String toString() {
    return 'node url: $url latency: $latency errors: $errors currentBlock: $currentBlock';
vjrj's avatar
vjrj committed
  }

  @override
vjrj's avatar
vjrj committed
  Map<String, dynamic> toJson() => _$NodeToJson(this);
vjrj's avatar
vjrj committed

  @override
vjrj's avatar
vjrj committed
  Node fromJson(Map<String, dynamic> json) => Node.fromJson(json);
vjrj's avatar
vjrj committed

  @override
  List<Object?> get props => <dynamic>[url];
vjrj's avatar
vjrj committed
}

vjrj's avatar
vjrj committed
List<Node> _splitList(String list) =>
    list.split(' ').map((String url) => Node(url: url)).toList();
vjrj's avatar
vjrj committed

vjrj's avatar
vjrj committed
List<Node> _readDotNodeConfig(String entry) => _splitList(dotenv.env[entry]!);

List<Node> defaultDuniterNodes = <Node>{
  ..._readDotNodeConfig('DUNITER_NODES'),
  ..._splitList(
      'duniter.pini.fr duniter.g1.pfouque.xyz fania.g1server.net g1.brussels.ovh g1.cgeek.fr g1.computhings.be g1.cuates.net g1.geragc.es g1.madeirawonders.com g1.rendall.fr g1.trentesaux.fr gibraleon.g1server.net vit.fdn.org')
}.toList();

vjrj's avatar
vjrj committed
List<Node> defaultCesiumPlusNodes = <Node>{
  ..._readDotNodeConfig('CESIUM_PLUS_NODES'),
  ..._splitList(
vjrj's avatar
vjrj committed
      'https://g1.data.brussels.ovh https://g1.data.e-is.pro https://g1.data.mithril.re https://g1.data.pini.fr https://g1.data.presles.fr https://g1.data.geragc.es')
vjrj's avatar
vjrj committed
}.toList();
List<Node> defaultGvaNodes = <Node>{
  ..._readDotNodeConfig('GVA_NODES'),
  ..._splitList(
      'https://g1.cuates.net/gva https://g1.madeirawonders.com/gva https://g1.brussels.ovh/gva https://g1.geragc.es/gva https://gva.seeds4c.org/gva')
}.toList();
vjrj's avatar
vjrj committed

// We test local duniter node in dev mode
/* List<Node> defaultGvaNodes = kReleaseMode
    ? readDotNodeConfig('GVA_NODES')
    : <Node>[const Node(url: 'http://localhost:30901/gva/')]
  ..addAll(readDotNodeConfig('GVA_NODES'));
// List<Node> defaultGvaNodes = readDotNodeConfig('GVA_NODES');
 : <Node>[const Node(url: 'http://localhost:30901/gva/')]
  ..addAll(readDotNodeConfig('GVA_NODES')); */