feat: zapret2 lists domain for learned to proxy ips
This commit is contained in:
7 files changed
+87
-8
No files matched your search
@@ -3898,6 +3898,11 @@ def _zapret_cutoff_dir():
|
||||
return env("ZAPRET_CUTOFF_DIR", f"{state_dir()}/zapret2-cutoff")
|
||||
|
||||
|
||||
def _zapret_direct_dir():
|
||||
"""Root's rule-sets from zapret2's state (zapret2/direct-sync.template.sh)."""
|
||||
return env("ZAPRET_DIRECT_DIR", f"{state_dir()}/zapret2-direct")
|
||||
|
||||
|
||||
def _zapret_auto_file(name):
|
||||
return os.path.join(_zapret_state_dir(), name)
|
||||
|
||||
@@ -4112,11 +4117,26 @@ def _zapret_status(host, verdicts=None):
|
||||
return ", ".join(parts)
|
||||
|
||||
|
||||
def _zapret_looked_up():
|
||||
"""{address: [names]}: what the addresses blocked outright were looked up by."""
|
||||
return {
|
||||
fields[0]: [name for name in fields[1].split(",") if name]
|
||||
for fields in _tsv(os.path.join(_zapret_direct_dir(), "names.tsv"))
|
||||
if len(fields) == 2
|
||||
}
|
||||
|
||||
|
||||
def _zapret_proxied(verdicts=None):
|
||||
"""[(name, why)] the proxy carries because zapret2 cannot fix them."""
|
||||
verdicts = _zapret_verdicts() if verdicts is None else verdicts
|
||||
looked_up = _zapret_looked_up()
|
||||
|
||||
def why(name, proto):
|
||||
names = looked_up.get(name) if proto == "ip" else None
|
||||
return f"{ZAPRET_PROXIED[proto]} ({', '.join(names)})" if names else ZAPRET_PROXIED[proto]
|
||||
|
||||
return [
|
||||
(name, ZAPRET_PROXIED[proto])
|
||||
(name, why(name, proto))
|
||||
for (name, proto), kind in sorted(verdicts.items())
|
||||
if (kind, proto) in (("unfixable", "tcp"), ("unfixable", "udp"), ("blocked", "ip"))
|
||||
]
|
||||
|
||||
@@ -1636,8 +1636,12 @@ class ZapretAutoTest(EnvTest):
|
||||
"unfixable\tchat.example\ttcp\trkn_tcp\t3\n"
|
||||
"blocked\t149.154.167.99\tip\tno answer\t4\n"
|
||||
"blocked\t203.0.113.9\tip\tno answer\t5\n"
|
||||
"reachable\t203.0.113.9\tip\t\t6\n",
|
||||
"reachable\t203.0.113.9\tip\t\t6\n"
|
||||
"blocked\t198.51.100.4\tip\tno answer\t7\n",
|
||||
)
|
||||
# The names an address was looked up by, from root's direct-sync; none for some.
|
||||
os.environ["ZAPRET_DIRECT_DIR"] = self.path("direct")
|
||||
self.write("direct/names.tsv", "149.154.167.99\t\n198.51.100.4\tapi.example,cdn.example\n")
|
||||
status, out, err = run(ctl.cmd_zapret_auto, "list")
|
||||
self.assertEqual(status, 0)
|
||||
self.assertIn("www.notion.so works", out)
|
||||
@@ -1645,6 +1649,7 @@ class ZapretAutoTest(EnvTest):
|
||||
self.assertIn("signal.org cut off after 16 KB: keeps the proxy's route", out)
|
||||
self.assertRegex(out, r"(?m)^ discord\.com +its QUIC: no strategy gets through$")
|
||||
self.assertRegex(out, r"(?m)^ 149\.154\.167\.99 +blocked by address$")
|
||||
self.assertRegex(out, r"(?m)^ 198\.51\.100\.4 +blocked by address \(api\.example, cdn\.example\)$")
|
||||
self.assertNotIn("203.0.113.9", out)
|
||||
self.assertIn("zapret auto retry", err)
|
||||
# retry clears it, and restarts zapret2 to unfreeze the rotation, when it runs.
|
||||
|
||||
Reference in new issue
Block a user