Big improve on selection of GVA endpoint at startup
This commit is contained in:
parent
0aa5d8a5af
commit
27ae053af0
|
@ -1,4 +1,5 @@
|
||||||
[
|
[
|
||||||
"https://g1.librelois.fr/gva",
|
"https://g1.librelois.fr/gva",
|
||||||
"http://localhost:30901/gva"
|
"https://duniter-gva.axiom-team.fr/gva",
|
||||||
|
"https://duniter-g1.p2p.legal/gva"
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,22 +32,8 @@ Future<void> main() async {
|
||||||
final HiveStore _store =
|
final HiveStore _store =
|
||||||
await HiveStore.open(path: '${appPath.path}/gqlCache');
|
await HiveStore.open(path: '${appPath.path}/gqlCache');
|
||||||
|
|
||||||
String _randomEndpoint;
|
// Get a valid GVA endpoint
|
||||||
int i = 0;
|
endPointGVA = await _homeProvider.getValidEndpoint();
|
||||||
do {
|
|
||||||
if (i >= 5) {
|
|
||||||
print('NO VALID ENDPOINT FOUND !');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i != 0) {
|
|
||||||
print(i.toString() + ' ème essai de recherche de endpoint GVA.');
|
|
||||||
await Future.delayed(Duration(milliseconds: 300));
|
|
||||||
}
|
|
||||||
_randomEndpoint = await _homeProvider.getRandomEndpoint();
|
|
||||||
i++;
|
|
||||||
} while (_randomEndpoint == 'HS');
|
|
||||||
|
|
||||||
endPointGVA = _randomEndpoint;
|
|
||||||
|
|
||||||
if (kReleaseMode && enableSentry) {
|
if (kReleaseMode && enableSentry) {
|
||||||
await SentryFlutter.init(
|
await SentryFlutter.init(
|
||||||
|
@ -55,12 +41,12 @@ Future<void> main() async {
|
||||||
options.dsn =
|
options.dsn =
|
||||||
'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110';
|
'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110';
|
||||||
},
|
},
|
||||||
appRunner: () => runApp(Gecko(_randomEndpoint, _store)),
|
appRunner: () => runApp(Gecko(endPointGVA, _store)),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print('Debug mode enabled: No sentry alerte');
|
print('Debug mode enabled: No sentry alerte');
|
||||||
|
|
||||||
runApp(Gecko(_randomEndpoint, _store));
|
runApp(Gecko(endPointGVA, _store));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -28,28 +29,49 @@ class HomeProvider with ChangeNotifier {
|
||||||
return version + '+' + buildNumber;
|
return version + '+' + buildNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> getRandomEndpoint() async {
|
Future<String> getValidEndpoint() async {
|
||||||
// TODO: Improve implemention of getRandomEndpoint()
|
List _listEndpoints = await rootBundle
|
||||||
// final _json = json.decode(await getJsonEndpoints());
|
.loadString('config/gva_endpoints.json')
|
||||||
// print('JSON !! :');
|
.then((jsonStr) => jsonDecode(jsonStr));
|
||||||
// print(_json);
|
|
||||||
// final _list = _json[];
|
int i = 0;
|
||||||
|
http.Response response;
|
||||||
|
_listEndpoints.shuffle();
|
||||||
|
String _endpoint;
|
||||||
|
int statusCode = 0;
|
||||||
|
|
||||||
|
final client = new HttpClient();
|
||||||
|
client.connectionTimeout = const Duration(seconds: 1);
|
||||||
|
|
||||||
|
do {
|
||||||
|
i++;
|
||||||
|
print(i.toString() + ' ème essai de recherche de endpoint GVA.');
|
||||||
|
try {
|
||||||
|
if (i > 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i != 0) {
|
||||||
|
await Future.delayed(Duration(milliseconds: 300));
|
||||||
|
}
|
||||||
|
response = await http
|
||||||
|
.post(_listEndpoints[i])
|
||||||
|
.timeout(const Duration(seconds: 1));
|
||||||
|
} on TimeoutException catch (_) {
|
||||||
|
print(_listEndpoints[i] + ' is timeout, next');
|
||||||
|
statusCode = 50;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
} on SocketException catch (_) {
|
||||||
|
print(_listEndpoints[i] + ' is a bad endpoint, next');
|
||||||
|
statusCode = 70;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_endpoint = _listEndpoints[i];
|
||||||
|
statusCode = response.statusCode;
|
||||||
|
print('Endpoint statutcode: ' + statusCode.toString());
|
||||||
|
} while (statusCode != 400);
|
||||||
|
|
||||||
final _listEndpoints = [
|
|
||||||
'https://g1.librelois.fr/gva',
|
|
||||||
'https://duniter-gva.axiom-team.fr/gva',
|
|
||||||
'https://duniter-g1.p2p.legal/gva'
|
|
||||||
];
|
|
||||||
final _endpoint = getRandomElement(_listEndpoints);
|
|
||||||
print('ENDPOINT: ' + _endpoint);
|
print('ENDPOINT: ' + _endpoint);
|
||||||
|
|
||||||
// http.post(_endpoint);
|
|
||||||
final response = await http.post(_endpoint);
|
|
||||||
if (response.statusCode != 400) {
|
|
||||||
print('Endpoint statutcode: ' + response.statusCode.toString());
|
|
||||||
return 'HS';
|
|
||||||
}
|
|
||||||
|
|
||||||
return _endpoint;
|
return _endpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ flutter:
|
||||||
|
|
||||||
assets:
|
assets:
|
||||||
- images/
|
- images/
|
||||||
- config/
|
- config/gva_endpoints.json
|
||||||
- assets/icon/gecko_final.png
|
- assets/icon/gecko_final.png
|
||||||
- assets/
|
- assets/
|
||||||
- assets/OpenSans-Regular.ttf
|
- assets/OpenSans-Regular.ttf
|
||||||
|
|
Loading…
Reference in New Issue