From 499c65f7199d442ce935dfca61dd4d477a8fee28 Mon Sep 17 00:00:00 2001 From: fuwa Date: Tue, 26 Nov 2019 17:05:43 +0800 Subject: [PATCH] show speed in peers --- cyberwow/lib/controller/rpc/rpc.dart | 42 ++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/cyberwow/lib/controller/rpc/rpc.dart b/cyberwow/lib/controller/rpc/rpc.dart index 9eb9fea..55ee776 100644 --- a/cyberwow/lib/controller/rpc/rpc.dart +++ b/cyberwow/lib/controller/rpc/rpc.dart @@ -134,14 +134,15 @@ Future> getConnectionsSimple() async { 'send_count', 'support_flags', - 'avg_download', - 'avg_upload', - 'current_download', - 'current_upload', + // 'avg_download', + // 'avg_upload', + // 'current_download', + // 'current_upload', 'rpc_credits_per_hash', 'state', 'recv_idle_time', 'send_idle_time', + 'incoming', ]; final _filteredConn = x..removeWhere @@ -149,13 +150,24 @@ Future> getConnectionsSimple() async { (k,v) => _remove.contains(k) ); - return _filteredConn.map + final _conn = _filteredConn.map ( (k, v) { if (k == 'connection_id') { return MapEntry(k, v.substring(0, config.hashLength) + '...'); } + const speedField = + [ + 'avg_download', + 'avg_upload', + 'current_download', + 'current_upload', + ]; + if (speedField.contains(k)) { + return MapEntry(k, '${v} kB'); + } + else if (k == 'live_time') { final _duration = Duration(seconds: v); format(Duration d) => d.toString().split('.').first.padLeft(8, "0"); @@ -167,6 +179,26 @@ Future> getConnectionsSimple() async { } } ); + + final List keys = + [ + 'address', + 'height', + 'live_time', + 'current_download', + 'current_upload', + 'avg_download', + 'avg_upload', + 'pruning_seed', + ] + .where((k) => _conn.keys.contains(k)) + .toList(); + + final _sortedConn = { + for (var k in keys) k: _conn[k] + }; + + return _sortedConn; } ).toList(); }