aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/socks.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-30 09:04:22 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-30 09:04:22 +1200
commit80860229209b4c6eb8384e1bca3cabdbe062fe6e (patch)
treeed0bb19910d81b9b8b8719b4c9fc34a40baa6919 /netlib/socks.py
parentb7a2fc85537dca60fb18d25965289d876bd3bd38 (diff)
downloadmitmproxy-80860229209b4c6eb8384e1bca3cabdbe062fe6e.tar.gz
mitmproxy-80860229209b4c6eb8384e1bca3cabdbe062fe6e.tar.bz2
mitmproxy-80860229209b4c6eb8384e1bca3cabdbe062fe6e.zip
Add a tiny utility class for keeping bi-directional mappings.
Use it in websocket and socks.
Diffstat (limited to 'netlib/socks.py')
-rw-r--r--netlib/socks.py60
1 files changed, 32 insertions, 28 deletions
diff --git a/netlib/socks.py b/netlib/socks.py
index a3c4e9a2..497b8eef 100644
--- a/netlib/socks.py
+++ b/netlib/socks.py
@@ -2,7 +2,7 @@ from __future__ import (absolute_import, print_function, division)
import socket
import struct
import array
-from . import tcp
+from . import tcp, utils
class SocksError(Exception):
@@ -11,40 +11,45 @@ class SocksError(Exception):
self.code = code
-class VERSION(object):
- SOCKS4 = 0x04
+VERSION = utils.BiDi(
+ SOCKS4 = 0x04,
SOCKS5 = 0x05
+)
-class CMD(object):
- CONNECT = 0x01
- BIND = 0x02
+CMD = utils.BiDi(
+ CONNECT = 0x01,
+ BIND = 0x02,
UDP_ASSOCIATE = 0x03
+)
-class ATYP(object):
- IPV4_ADDRESS = 0x01
- DOMAINNAME = 0x03
+ATYP = utils.BiDi(
+ IPV4_ADDRESS = 0x01,
+ DOMAINNAME = 0x03,
IPV6_ADDRESS = 0x04
-
-
-class REP(object):
- SUCCEEDED = 0x00
- GENERAL_SOCKS_SERVER_FAILURE = 0x01
- CONNECTION_NOT_ALLOWED_BY_RULESET = 0x02
- NETWORK_UNREACHABLE = 0x03
- HOST_UNREACHABLE = 0x04
- CONNECTION_REFUSED = 0x05
- TTL_EXPIRED = 0x06
- COMMAND_NOT_SUPPORTED = 0x07
- ADDRESS_TYPE_NOT_SUPPORTED = 0x08
-
-
-class METHOD(object):
- NO_AUTHENTICATION_REQUIRED = 0x00
- GSSAPI = 0x01
- USERNAME_PASSWORD = 0x02
+)
+
+
+REP = utils.BiDi(
+ SUCCEEDED = 0x00,
+ GENERAL_SOCKS_SERVER_FAILURE = 0x01,
+ CONNECTION_NOT_ALLOWED_BY_RULESET = 0x02,
+ NETWORK_UNREACHABLE = 0x03,
+ HOST_UNREACHABLE = 0x04,
+ CONNECTION_REFUSED = 0x05,
+ TTL_EXPIRED = 0x06,
+ COMMAND_NOT_SUPPORTED = 0x07,
+ ADDRESS_TYPE_NOT_SUPPORTED = 0x08,
+)
+
+
+METHOD = utils.BiDi(
+ NO_AUTHENTICATION_REQUIRED = 0x00,
+ GSSAPI = 0x01,
+ USERNAME_PASSWORD = 0x02,
NO_ACCEPTABLE_METHODS = 0xFF
+)
def _read(f, n):
@@ -146,4 +151,3 @@ class Message(object):
"Unknown ATYP: %s" % self.atyp
)
f.write(struct.pack("!H", self.addr.port))
-