From feff053f0949677e0001aeac4c925bb4becbf1a4 Mon Sep 17 00:00:00 2001 From: fuwa Date: Tue, 23 Jul 2019 02:25:38 +0000 Subject: [PATCH] tune rpc --- cyberwow/lib/controller/refresh.dart | 6 +++--- cyberwow/lib/controller/rpc.dart | 6 +++++- cyberwow/lib/state.dart | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cyberwow/lib/controller/refresh.dart b/cyberwow/lib/controller/refresh.dart index c0d84c2..4449fe0 100644 --- a/cyberwow/lib/controller/refresh.dart +++ b/cyberwow/lib/controller/refresh.dart @@ -29,14 +29,14 @@ import '../config.dart'; typedef GetNotificationFunc = AppLifecycleState Function(); -Stream pull(GetNotificationFunc getNotification) async* { +Stream pull(GetNotificationFunc getNotification, String puller) async* { while (true) { final _appState = getNotification(); - log.finer('refresh targetHeight: app state: ${_appState}'); + log.finer('refresh pull by ${puller}: app state: ${_appState}'); if (_appState == AppLifecycleState.resumed) { yield null; - await Future.delayed(const Duration(milliseconds: 400), () => null); + await Future.delayed(const Duration(milliseconds: 1000), () => null); } else { await Future.delayed(const Duration(seconds: 2), () => null); } diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart index 139e2d7..0d0e572 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc.dart @@ -27,14 +27,18 @@ import 'package:flutter/foundation.dart'; import '../config.dart'; +int rpcID = 0; + Future rpc(String method) async { final url = 'http://127.0.0.1:${config.port}/json_rpc'; + rpcID += 1; + final body = json.encode ( { 'jsonrpc': '2.0', - 'id': '0', + 'id': rpcID.toString(), 'method': method, } ); diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 05112c2..33a782a 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -164,8 +164,8 @@ class SyncingState extends HookedState { } Future checkSync() async { - await for (var _null in refresh.pull(getNotification)) { - log.finer('syncing: checkSync loop'); + await for (var _null in refresh.pull(getNotification, 'syncingState')) { + log.finer('SyncingState: checkSync loop'); // here doc is wrong, targetHeight could match height when synced // potential bug, targetHeight could be smaller then height @@ -219,12 +219,12 @@ class SyncedState extends HookedState { logStdout(); Future checkSync() async { - await for (var _null in refresh.pull(getNotification)) { + await for (var _null in refresh.pull(getNotification, 'syncedState')) { if (await daemon.isNotSynced()) { synced = false; break; } - // print('synced loop'); + // log.finer('SyncedState: checkSync loop'); height = await rpc.height(); connected = await daemon.isConnected(); getInfo = await rpc.getInfoString(); @@ -270,7 +270,7 @@ class ReSyncingState extends HookedState { } Future checkSync() async { - await for (var _null in refresh.pull(getNotification)) { + await for (var _null in refresh.pull(getNotification, 'ReSyncingState')) { if (await daemon.isSynced()) { synced = true;