1 |
On 01/25/2015 06:00 AM, Michał Górny wrote: |
2 |
> diff --git a/bin/socks5-server.py b/bin/socks5-server.py |
3 |
> new file mode 100644 |
4 |
> index 0000000..c079018 |
5 |
> --- /dev/null |
6 |
> +++ b/bin/socks5-server.py |
7 |
> @@ -0,0 +1,218 @@ |
8 |
> +#!/usr/bin/env python |
9 |
> +# SOCKSv5 proxy server for network-sandbox |
10 |
> +# Copyright 2015 Gentoo Foundation |
11 |
> +# Distributed under the terms of the GNU General Public License v2 |
12 |
> + |
13 |
> +import asyncore |
14 |
> +import errno |
15 |
> +import socket |
16 |
> +import struct |
17 |
> +import sys |
18 |
> + |
19 |
> + |
20 |
> +class ProxyConnection(asyncore.dispatcher_with_send): |
21 |
> + _addr = None |
22 |
> + _connected = False |
23 |
> + _family = socket.AF_INET |
24 |
> + _proxy_conn = None |
25 |
> + |
26 |
> + def __init__(self, proxy_conn): |
27 |
> + self._proxy_conn = proxy_conn |
28 |
> + asyncore.dispatcher_with_send.__init__(self) |
29 |
> + self.create_socket(self._family, socket.SOCK_STREAM) |
30 |
> + |
31 |
> + def start_connection(self, host, port): |
32 |
> + try: |
33 |
> + self.connect((host, port)) |
34 |
> + except: |
35 |
> + self.handle_error() |
36 |
> + |
37 |
> + def handle_read(self): |
38 |
> + buf = self.recv(4096) |
39 |
> + self._proxy_conn.send(buf) |
40 |
|
41 |
The self.recv calls should probably handle BlockingIOError, since the |
42 |
docs say it can be raised "even though select.select() or select.poll() |
43 |
has reported the socket ready for reading". |
44 |
-- |
45 |
Thanks, |
46 |
Zac |