Benchmark | ||
chart | ||
extensions/chromium | ||
pac-generator | ||
.gitignore | ||
package.json | ||
README.md |
Anti-Censorship Solution based on PAC-Script
Censorship in Russia
Censorship in Russia plagues the Freedoms of Information and Speech, slowly building analogue of China Golden Shield.
For good or bad, it blocks Main Kampf, lolicon (rearly distinguishing from hentai) and critics of Putin.
Looking at how Russian government distorts TV and blocks Internet, I decided to write an Anti-Censorship extension for Chomium.
I believe the freedom of information is a virtue and important information mustn't be blocked based on political or other subjective views.
Task Technical Formulation
You have a list of blocked domains.
Per each outcoming request you have to check whether host is a subdomain of the blocked domains.
If host is blocked, you have serve it via proxy.
PAC (proxy auto-config) is executed on each request.
If it returns PROXY address
to the browser then proxy is used, otherwise it returns DIRECT
.
Is_subdomain_of( host, blocked_hosts )
You have check host belongs to subdomains of the blocked hosts
very fast.
This check is executed on each request. You should watch memeory consumption also.
The naive solution is to keep array of blocked ips and check if the host resolves to one of the ips.
You may do it with indexOf
, binary search, etc.
The shortcoming of every ip solution is that some providers resolve blocked hosts to wrong ips, so we eventually need list of hosts.
- IPs indexOf – Blocked IP is search by
indexOf
- IPs binary – Blocked IP is search by binary search. For some reason miss time slightly increased.
- IPs switch – Simply
switch(Blocked_IP) { case1: ... caseN: return true }
. Works even better than binary search. Magic. - Hosts switch – Radix trie built on
switch
. Comparable to IPs switch.