From e17f9d49f5b604f386eff640b197c43ce1052980 Mon Sep 17 00:00:00 2001 From: vjrj <vjrj@comunes.org> Date: Sun, 16 Jul 2023 01:37:21 +0200 Subject: [PATCH] Select more updated Cesium Plus node --- lib/g1/api.dart | 19 +++++++++++++++++-- .../widgets/debug_nodes/debug_node_list.dart | 2 +- pubspec.yaml | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/g1/api.dart b/lib/g1/api.dart index 1a605fd0..d6def16b 100644 --- a/lib/g1/api.dart +++ b/lib/g1/api.dart @@ -427,10 +427,25 @@ Future<NodeCheck> _pingNode(String node, NodeType type) async { } } else if (type == NodeType.cesiumPlus) { // see: http://g1.data.e-is.pro/network/peering - await http - .get(Uri.parse('$node/network/peering')) + final Response response = await http + .get(Uri.parse('$node/node/stats')) // Decrease http timeout during ping .timeout(timeout); + if (response.statusCode == 200) { + try { + final Map<String, dynamic> json = + jsonDecode(response.body.replaceAll('"cluster"{', '"cluster": {')) + as Map<String, dynamic>; + currentBlock = ((((json['stats'] as Map<String, dynamic>)['cluster'] + as Map<String, dynamic>)['indices'] + as Map<String, dynamic>)['docs'] + as Map<String, dynamic>)['count'] as int; + } catch (e) { + loggerDev('Cannot parse node/stats $e'); + } + } else { + latency = wrongNodeDuration; + } stopwatch.stop(); latency = stopwatch.elapsed; } else { diff --git a/lib/ui/widgets/debug_nodes/debug_node_list.dart b/lib/ui/widgets/debug_nodes/debug_node_list.dart index 1cf4d7db..5b1e8ca0 100644 --- a/lib/ui/widgets/debug_nodes/debug_node_list.dart +++ b/lib/ui/widgets/debug_nodes/debug_node_list.dart @@ -38,7 +38,7 @@ class DebugNodeList extends StatelessWidget { title: Text(node.url), subtitle: node.latency < wrongNode ? Text( - '${type != NodeType.cesiumPlus ? 'Current block: ${node.currentBlock}, ' : ''}errors: ${node.errors}, latency (ms): ${node.latency}') + '${type != NodeType.cesiumPlus ? 'Current block: ${node.currentBlock}, ' : 'Current docs: ${node.currentBlock}, '}errors: ${node.errors}, latency (ms): ${node.latency}') : null, leading: node.currentBlock == currentBlock && node.latency < wrongNode diff --git a/pubspec.yaml b/pubspec.yaml index 82396f0f..a972d797 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 0.2.3 +version: 0.2.4-SNAPSHOT environment: sdk: ">=2.17.1 <3.0.0" -- GitLab