This commit is contained in:
2021-05-08 01:05:49 +08:00
parent c3ee2b8bd7
commit 88b7b52641
2 changed files with 43 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ import 'dart:io';
class HostAndPort {
String host;
int port;
HostAndPort({this.host, this.port});
}
class ManageConfig {
@@ -24,9 +26,29 @@ class ProxyConfig {
ProxyConfig parseProxyConfig(String config) {
final jsonConfig = json.decode(config);
final managementConfig = jsonConfig['managementConfig'];
print(managementConfig);
// print(jsonConfig);
return null;
}
Future<ProxyConfig> loadProxyConfig(String configFile/*, {List<String> files} ?? */) async {
HostAndPort parseHostAndPort(String hnp) {
final indexOfC = hnp.indexOf(":");
if (indexOfC < 0) {
throw 'Missing port: ' + hnp;
}
var host = hnp.substring(0, indexOfC);
final port = int.parse(hnp.substring(indexOfC + 1));
if (host.isEmpty) {
host = "0.0.0.0";
}
return HostAndPort(host: host, port: port);
}
Future<ProxyConfig> loadProxyConfig(String configFile
/*, {List<String> files} ?? */) async {
final configFn = File(configFile);
if (!await configFn.exists()) {
throw 'Config file not found: ' + configFile;

View File

@@ -8,6 +8,26 @@ void main(List<String> arguments) {
final targetHost = "";
final targetPort = 443;
parseProxyConfig('''{
"managementConfig": { "listen": "127.0.0.1:8888" },
"tcpListens": [
{
"listen": ":8443",
"backend": "101.132.122.240:443",
"allowIps": ["127.0.0.1"]
}
]
}''');
parseProxyConfig('''{
"tcpListens": [
{
"listen": ":8443",
"backend": "101.132.122.240:443",
"allowIps": ["127.0.0.1"]
}
]
}''');
// TODO ...
print('Hello world!');
}