Skip to content

Commit 756a55e

Browse files
authored
v1.7.3
scheduling algorithm
1 parent 244a764 commit 756a55e

1 file changed

Lines changed: 93 additions & 68 deletions

File tree

README.rst

Lines changed: 93 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,63 @@ Features
7272
- PyPy3 support with JIT speedup.
7373
- System proxy auto-setting support.
7474
- UDP proxy client/server support.
75+
- Schedule (load balance) among remote servers.
7576

7677
.. _One-Time-Auth: https://shadowsocks.org/en/spec/one-time-auth.html
7778

78-
Python3
79-
-------
80-
81-
*Python 3.5* added new syntax **async def** and **await** to make asyncio programming easier. *Python 3.6* added new syntax **formatted string literals**. This tool was to demonstrate these new syntax, so the minimal Python requirement was **3.6**.
82-
83-
From **pproxy** 1.1.0, the minimal Python requirement is **3.3**, since old python versions are still widely used and PyPy3 only has 3.3 support currently. *Python 2* will not be supported in the future.
84-
85-
From **proxy** 1.3.0, the minimal Python requirement is **3.6**, since **Python 3.7** make the **async**/**await**/ reserved words, we cannot make pproxy compatible with older versions.
86-
87-
PyPy3
88-
-----
79+
Protocols
80+
---------
8981

90-
.. code:: rst
82+
+-------------------+------------+------------+------------+------------+--------------+
83+
| Name | TCP server | TCP client | UDP server | UDP client | scheme |
84+
+===================+============+============+============+============+==============+
85+
| http (connect) ||| | | http:// |
86+
+-------------------+------------+------------+------------+------------+--------------+
87+
| http (get,post) ||| | | http:// |
88+
+-------------------+------------+------------+------------+------------+--------------+
89+
| https ||| | | http+ssl:// |
90+
+-------------------+------------+------------+------------+------------+--------------+
91+
| socks4 ||| | | socks4:// |
92+
+-------------------+------------+------------+------------+------------+--------------+
93+
| socks5 ||| ✔ udp-only | ✔ udp-only | socks5:// |
94+
+-------------------+------------+------------+------------+------------+--------------+
95+
| shadowsocks ||||| ss:// |
96+
+-------------------+------------+------------+------------+------------+--------------+
97+
| shadowsocks aead ||| | | ss:// |
98+
+-------------------+------------+------------+------------+------------+--------------+
99+
| shadowsocksR ||| | | ssr:// |
100+
+-------------------+------------+------------+------------+------------+--------------+
101+
| iptables nat || | | | redir:// |
102+
+-------------------+------------+------------+------------+------------+--------------+
103+
| pfctl nat (macos) || | | | pf:// |
104+
+-------------------+------------+------------+------------+------------+--------------+
105+
| echo || || | echo:// |
106+
+-------------------+------------+------------+------------+------------+--------------+
107+
| tunnel ||||| tunnel:// |
108+
| (raw socket) | | | | | tunnel{ip}://|
109+
+-------------------+------------+------------+------------+------------+--------------+
110+
| AUTO DETECT || || | a+b+c+d:// |
111+
+-------------------+------------+------------+------------+------------+--------------+
91112

92-
$ pypy3 -m ensurepip
93-
$ pypy3 -m pip install asyncio pproxy
113+
Scheduling Algorithms
114+
---------------------
115+
116+
+-------------------+------------+------------+------------+------------+
117+
| Name | TCP | UDP | Parameter | Default |
118+
+===================+============+============+============+============+
119+
| first_available ||| -s fa ||
120+
+-------------------+------------+------------+------------+------------+
121+
| round_robin ||| -s rr | |
122+
+-------------------+------------+------------+------------+------------+
123+
| random_choice ||| -s rc | |
124+
+-------------------+------------+------------+------------+------------+
125+
| least_connection || | -s lc | |
126+
+-------------------+------------+------------+------------+------------+
94127

95128
Requirement
96129
-----------
97130

98-
pycryptodome_ is an optional library to enable faster (C version) cipher. **pproxy** has many built-in pure python ciphers. They are lightweight and stable, but slower than C ciphers. After speedup with PyPy_, the pure python ciphers can get similar performance as C version. If the performance is important and don't have PyPy_, install pycryptodome_ instead.
131+
pycryptodome_ is an optional library to enable faster (C version) cipher. **pproxy** has many built-in pure python ciphers. They are lightweight and stable, but slower than C ciphers. After speedup with PyPy_, pure python ciphers can get similar performance as C version. If the performance is important and don't have PyPy_, install pycryptodome_ instead.
99132

100133
These are some performance benchmarks between Python and C ciphers (dataset: 8M):
101134

@@ -107,6 +140,13 @@ These are some performance benchmarks between Python and C ciphers (dataset: 8M)
107140
| chacha20-py | 48.86 secs |
108141
+---------------------+----------------+
109142

143+
PyPy3 Quickstart:
144+
145+
.. code:: rst
146+
147+
$ pypy3 -m ensurepip
148+
$ pypy3 -m pip install asyncio pproxy
149+
110150
.. _pycryptodome: https://pycryptodome.readthedocs.io/en/latest/src/introduction.html
111151
.. _PyPy: http://pypy.org
112152

@@ -124,57 +164,24 @@ Usage
124164
protocols: http,socks4,socks5,shadowsocks,shadowsocksr,redirect,pf,tunnel
125165
126166
optional arguments:
127-
-h, --help show this help message and exit
128-
-l LISTEN tcp server uri (default: http+socks4+socks5://:8080/)
129-
-r RSERVER tcp remote server uri (default: direct)
130-
-ul ULISTEN udp server setting uri (default: none)
131-
-ur URSERVER udp remote server uri (default: direct)
132-
-b BLOCK block regex rules
133-
-a ALIVED interval to check remote alive (default: no check)
134-
-v print verbose output
135-
--ssl SSLFILE certfile[,keyfile] if server listen in ssl mode
136-
--pac PAC http PAC path
137-
--get GETS http custom {path,file}
138-
--sys change system proxy setting (mac, windows)
139-
--test TEST test this url for all remote proxies and exit
140-
--version show program's version number and exit
167+
-h, --help show this help message and exit
168+
-l LISTEN tcp server uri (default: http+socks4+socks5://:8080/)
169+
-r RSERVER tcp remote server uri (default: direct)
170+
-ul ULISTEN udp server setting uri (default: none)
171+
-ur URSERVER udp remote server uri (default: direct)
172+
-b BLOCK block regex rules
173+
-a ALIVED interval to check remote alive (default: no check)
174+
-s {fa,rr,rc,lc} scheduling algorithm (default: first_available)
175+
-v print verbose output
176+
--ssl SSLFILE certfile[,keyfile] if server listen in ssl mode
177+
--pac PAC http PAC path
178+
--get GETS http custom {path,file}
179+
--sys change system proxy setting (mac, windows)
180+
--test TEST test this url for all remote proxies and exit
181+
--version show program's version number and exit
141182
142183
Online help: <https://github.com/qwj/python-proxy>
143184
144-
Protocols
145-
---------
146-
147-
+-------------------+------------+------------+------------+------------+--------------+
148-
| Name | TCP server | TCP client | UDP server | UDP client | scheme |
149-
+===================+============+============+============+============+==============+
150-
| http (connect) ||| | | http:// |
151-
+-------------------+------------+------------+------------+------------+--------------+
152-
| http (get,post) ||| | | http:// |
153-
+-------------------+------------+------------+------------+------------+--------------+
154-
| https ||| | | http+ssl:// |
155-
+-------------------+------------+------------+------------+------------+--------------+
156-
| socks4 ||| | | socks4:// |
157-
+-------------------+------------+------------+------------+------------+--------------+
158-
| socks5 ||| ✔ udp-only | ✔ udp-only | socks5:// |
159-
+-------------------+------------+------------+------------+------------+--------------+
160-
| shadowsocks ||||| ss:// |
161-
+-------------------+------------+------------+------------+------------+--------------+
162-
| shadowsocks aead ||| | | ss:// |
163-
+-------------------+------------+------------+------------+------------+--------------+
164-
| shadowsocksR ||| | | ssr:// |
165-
+-------------------+------------+------------+------------+------------+--------------+
166-
| iptables nat || | | | redir:// |
167-
+-------------------+------------+------------+------------+------------+--------------+
168-
| pfctl nat (macos) || | | | pf:// |
169-
+-------------------+------------+------------+------------+------------+--------------+
170-
| echo || || | echo:// |
171-
+-------------------+------------+------------+------------+------------+--------------+
172-
| tunnel ||||| tunnel:// |
173-
| (raw socket) | | | | | tunnel{ip}://|
174-
+-------------------+------------+------------+------------+------------+--------------+
175-
| AUTO DETECT || || | a+b+c+d:// |
176-
+-------------------+------------+------------+------------+------------+--------------+
177-
178185
URI Syntax
179186
----------
180187

@@ -354,7 +361,7 @@ Examples
354361

355362
.. code:: rst
356363
357-
$ pproxy -r http://aa.bb.cc.dd:8080?rules -v
364+
$ pproxy -r http://aa.bb.cc.dd:8080?rules -vv
358365
Serving on :8080 by http,socks4,socks5
359366
http ::1:57768 -> http aa.bb.cc.dd:8080 -> www.googleapis.com:443
360367
http ::1:57772 -> www.yahoo.com:80
@@ -368,7 +375,7 @@ Examples
368375

369376
.. code:: rst
370377
371-
$ pproxy -l ss://:8888 -r ss://chacha20:cipher_key@aa.bb.cc.dd:12345 -v
378+
$ pproxy -l ss://:8888 -r ss://chacha20:cipher_key@aa.bb.cc.dd:12345 -vv
372379
373380
Next, run pproxy.py remotely on server "aa.bb.cc.dd". The base64 encoded string of "chacha20:cipher_key" is also supported:
374381

@@ -437,7 +444,7 @@ Examples
437444
.. code:: rst
438445
439446
$ sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j REDIRECT --to-ports 5555
440-
$ pproxy -l redir://:5555 -r http://remote_http_server:3128 -v
447+
$ pproxy -l redir://:5555 -r http://remote_http_server:3128 -vv
441448
442449
The above example illustrates how to redirect all local output tcp traffic with destination port 80 to localhost port 5555 listened by **pproxy**, and then tunnel the traffic to remote http proxy.
443450

@@ -449,7 +456,7 @@ Examples
449456
rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
450457
pass out on en0 route-to lo0 inet proto tcp from any to any port 80 keep state
451458
^D
452-
$ sudo pproxy -l pf://:8080 -r socks5://remote_socks5_server:1324 -v
459+
$ sudo pproxy -l pf://:8080 -r socks5://remote_socks5_server:1324 -vv
453460
454461
Make sure **pproxy** runs in root mode (sudo), otherwise it cannot redirect pf packet.
455462

@@ -491,8 +498,26 @@ Examples
491498

492499
.. code:: rst
493500
494-
$ pproxy -ul tunnel{8.8.8.8}://:53 -ur ss://remote_server:13245
501+
$ pproxy -ul tunnel{8.8.8.8}://:53 -ur ss://remote_server:13245 -vv
495502
UDP tunnel 127.0.0.1:60573 -> ss remote_server:13245 -> 8.8.8.8:53
496503
UDP tunnel 127.0.0.1:60574 -> ss remote_server:13245 -> 8.8.8.8:53
497504
...
498505
$ nslookup google.com localhost
506+
507+
- Load balance example
508+
509+
Specify multiple -r server, and a scheduling algorithm (rr = round_robin, rc = random_choice, lc = least_connection):
510+
511+
.. code:: rst
512+
513+
$ pproxy -r http://server1 -r ss://server2 -r socks5://server3 -s rr -vv
514+
http ::1:42356 -> http server1 -> google.com:443
515+
http ::1:42357 -> ss server2 -> google.com:443
516+
http ::1:42358 -> socks5 server3 -> google.com:443
517+
http ::1:42359 -> http server1 -> google.com:443
518+
...
519+
$ pproxy -ul tunnel://:53 -ur tunnel://8.8.8.8:53 -ur tunnel://8.8.4.4:53 -s rc -vv
520+
UDP tunnel ::1:35378 -> tunnel 8.8.8.8:53
521+
UDP tunnel ::1:35378 -> tunnel 8.8.4.4:53
522+
...
523+

0 commit comments

Comments
 (0)