Commit 1c1a8ed9 authored by Mygod's avatar Mygod

Flatten ACL with openConnection

parent 0c93a0eb
...@@ -32,6 +32,7 @@ import java.io.File ...@@ -32,6 +32,7 @@ import java.io.File
import java.io.IOException import java.io.IOException
import java.io.Reader import java.io.Reader
import java.net.URL import java.net.URL
import java.net.URLConnection
class Acl { class Acl {
companion object { companion object {
...@@ -151,11 +152,11 @@ class Acl { ...@@ -151,11 +152,11 @@ class Acl {
fromReader(getFile(id).bufferedReader()) fromReader(getFile(id).bufferedReader())
} catch (_: IOException) { this } } catch (_: IOException) { this }
fun flatten(depth: Int): Acl { suspend fun flatten(depth: Int, connect: suspend (URL) -> URLConnection): Acl {
if (depth > 0) for (url in urls.asIterable()) { if (depth > 0) for (url in urls.asIterable()) {
val child = Acl() val child = Acl()
try { try {
child.fromReader(url.openStream().bufferedReader(), bypass).flatten(depth - 1) child.fromReader(connect(url).getInputStream().bufferedReader(), bypass).flatten(depth - 1, connect)
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
continue continue
......
...@@ -80,7 +80,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -80,7 +80,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
profile.method = proxy[3].trim() profile.method = proxy[3].trim()
} }
if (route == Acl.CUSTOM_RULES) Acl.save(Acl.CUSTOM_RULES, Acl.customRules.flatten(10)) if (route == Acl.CUSTOM_RULES) Acl.save(Acl.CUSTOM_RULES, Acl.customRules.flatten(10, service::openConnection))
// it's hard to resolve DNS on a specific interface so we'll do it here // it's hard to resolve DNS on a specific interface so we'll do it here
if (profile.host.parseNumericAddress() == null) profile.host = withTimeoutOrNull(10_000) { if (profile.host.parseNumericAddress() == null) profile.host = withTimeoutOrNull(10_000) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment