From 88b7b526414ca009eca8fb1488d0e5f8cb96407c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 8 May 2021 01:05:49 +0800 Subject: [PATCH] update --- bin/config.dart | 24 ++++++++++++++++++- bin/{simple_dart_tcp_proxy.dart => main.dart} | 20 ++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) rename bin/{simple_dart_tcp_proxy.dart => main.dart} (56%) diff --git a/bin/config.dart b/bin/config.dart index f710b40..6c21cbd 100644 --- a/bin/config.dart +++ b/bin/config.dart @@ -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 loadProxyConfig(String configFile/*, {List 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 loadProxyConfig(String configFile + /*, {List files} ?? */) async { final configFn = File(configFile); if (!await configFn.exists()) { throw 'Config file not found: ' + configFile; diff --git a/bin/simple_dart_tcp_proxy.dart b/bin/main.dart similarity index 56% rename from bin/simple_dart_tcp_proxy.dart rename to bin/main.dart index 314be67..b90bb5e 100644 --- a/bin/simple_dart_tcp_proxy.dart +++ b/bin/main.dart @@ -8,6 +8,26 @@ void main(List 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!'); }