Browse Source

add MYSQL_TRANSFER_MUL

add protocol_param (for auth_simple)
dev
BreakWa11 9 years ago
parent
commit
b5da4bc86a
  1. 1
      Config.py
  2. 10
      db_transfer.py
  3. 14
      shadowsocks/obfsplugin/auth.py
  4. 8
      shadowsocks/obfsplugin/http_simple.py
  5. 5
      shadowsocks/server.py
  6. 11
      shadowsocks/shell.py
  7. 9
      shadowsocks/tcprelay.py

1
Config.py

@ -4,6 +4,7 @@ MYSQL_PORT = 3306
MYSQL_USER = 'ss'
MYSQL_PASS = 'ss'
MYSQL_DB = 'shadowsocks'
MYSQL_TRANSFER_MUL = 1.0
MANAGE_PASS = 'ss233333333'
#if you want manage in other server you should set this value to global ip

10
db_transfer.py

@ -37,14 +37,16 @@ class DbTransfer(object):
continue
elif last_transfer[id][0] <= curr_transfer[id][0] and \
last_transfer[id][1] <= curr_transfer[id][1]:
dt_transfer[id] = [curr_transfer[id][0] - last_transfer[id][0],
curr_transfer[id][1] - last_transfer[id][1]]
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.MYSQL_TRANSFER_MUL),
int((curr_transfer[id][1] - last_transfer[id][1]) * Config.MYSQL_TRANSFER_MUL)]
else:
dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]
dt_transfer[id] = [int(curr_transfer[id][0] * Config.MYSQL_TRANSFER_MUL),
int(curr_transfer[id][1] * Config.MYSQL_TRANSFER_MUL)]
else:
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
continue
dt_transfer[id] = [curr_transfer[id][0], curr_transfer[id][1]]
dt_transfer[id] = [int(curr_transfer[id][0] * Config.MYSQL_TRANSFER_MUL),
int(curr_transfer[id][1] * Config.MYSQL_TRANSFER_MUL)]
self.last_get_transfer = curr_transfer
query_head = 'UPDATE user'

14
shadowsocks/obfsplugin/auth.py

@ -127,13 +127,16 @@ class obfs_auth_data(object):
self.startup_time = int(time.time() - 30) & 0xFFFFFFFF
self.local_client_id = b''
self.connection_id = 0
self.max_client = 16 # max active client count
self.max_buffer = max(self.max_client, 256) # max client id buffer size
self.set_max_client(16) # max active client count
def update(self, client_id, connection_id):
if client_id in self.client_id:
self.client_id[client_id].update()
def set_max_client(self, max_client):
self.max_client = max_client
self.max_buffer = max(self.max_client * 2, 256)
def insert(self, client_id, connection_id):
if client_id not in self.client_id or not self.client_id[client_id].enable:
active = 0
@ -184,6 +187,13 @@ class auth_simple(verify_base):
def init_data(self):
return obfs_auth_data()
def set_server_info(self, server_info):
self.server_info = server_info
try:
max_client = int(server_info.protocol_param)
except:
pass
def pack_data(self, buf):
if len(buf) == 0:
return b''

8
shadowsocks/obfsplugin/http_simple.py

@ -101,7 +101,7 @@ class http_simple(plain.plain):
if self.server_info.port != 80:
port = b':' + common.to_bytes(str(self.server_info.port))
http_head = b"GET /" + self.encode_head(headdata) + b" HTTP/1.1\r\n"
http_head += b"Host: " + (self.server_info.param or self.server_info.host) + port + b"\r\n"
http_head += b"Host: " + (self.server_info.obfs_param or self.server_info.host) + port + b"\r\n"
http_head += b"User-Agent: " + random.choice(self.user_agent) + b"\r\n"
http_head += b"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Encoding: gzip, deflate\r\nDNT: 1\r\nConnection: keep-alive\r\n\r\n"
self.has_sent_header = True
@ -171,8 +171,8 @@ class http_simple(plain.plain):
else:
return (b'', True, False)
datas = buf.split(b'\r\n\r\n', 1)
if datas:
if b'\r\n\r\n' in buf:
datas = buf.split(b'\r\n\r\n', 1)
ret_buf = self.get_data_from_http_header(buf)
if len(datas) > 1:
ret_buf += datas[1]
@ -205,7 +205,7 @@ class http2_simple(plain.plain):
port = b':' + common.to_bytes(str(self.server_info.port))
self.has_sent_header = True
http_head = b"GET / HTTP/1.1\r\n"
http_head += b"Host: " + (self.server_info.param or self.server_info.host) + port + b"\r\n"
http_head += b"Host: " + (self.server_info.obfs_param or self.server_info.host) + port + b"\r\n"
http_head += b"Connection: Upgrade, HTTP2-Settings\r\nUpgrade: h2c\r\n"
http_head += b"HTTP2-Settings: " + base64.urlsafe_b64encode(buf) + b"\r\n"
return http_head + b"\r\n"

5
shadowsocks/server.py

@ -69,6 +69,8 @@ def main():
del config['port_password']
for port, password_obfs in port_password.items():
protocol = config.get("protocol", 'origin')
protocol_param = config.get("protocol_param", '')
obfs = config.get("obfs", 'plain')
obfs_param = config.get("obfs_param", '')
if type(password_obfs) == list:
password = password_obfs[0]
@ -80,7 +82,6 @@ def main():
obfs_param = password_obfs.get('obfs_param', '')
else:
password = password_obfs
obfs = config["obfs"]
a_config = config.copy()
ipv6_ok = False
logging.info("server start with protocol[%s] password [%s] method [%s] obfs [%s] obfs_param [%s]" %
@ -92,6 +93,7 @@ def main():
a_config['server_port'] = int(port)
a_config['password'] = password
a_config['protocol'] = protocol
a_config['protocol_param'] = protocol_param
a_config['obfs'] = obfs
a_config['obfs_param'] = obfs_param
a_config['server'] = a_config['server_ipv6']
@ -109,6 +111,7 @@ def main():
a_config['server_port'] = int(port)
a_config['password'] = password
a_config['protocol'] = protocol
a_config['protocol_param'] = protocol_param
a_config['obfs'] = obfs
a_config['obfs_param'] = obfs_param
logging.info("starting server at %s:%d" %

11
shadowsocks/shell.py

@ -130,11 +130,11 @@ def get_config(is_local):
logging.basicConfig(level=logging.INFO,
format='%(levelname)-s: %(message)s')
if is_local:
shortopts = 'hd:s:b:p:k:l:m:o:c:t:vq'
shortopts = 'hd:s:b:p:k:l:m:P:o:G:g:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'user=',
'version']
else:
shortopts = 'hd:s:p:k:m:o:c:t:vq'
shortopts = 'hd:s:p:k:m:P:o:G:g:c:t:vq'
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
'forbidden-ip=', 'user=', 'manager-address=', 'version']
try:
@ -168,8 +168,14 @@ def get_config(is_local):
config['server'] = to_str(value)
elif key == '-m':
config['method'] = to_str(value)
elif key == '-P':
config['protocol'] = to_str(value)
elif key == '-o':
config['obfs'] = to_str(value)
elif key == '-G':
config['protocol_param'] = to_str(value)
elif key == '-g':
config['obfs_param'] = to_str(value)
elif key == '-b':
config['local_address'] = to_str(value)
elif key == '-v':
@ -219,6 +225,7 @@ def get_config(is_local):
config['password'] = to_bytes(config.get('password', b''))
config['method'] = to_str(config.get('method', 'aes-256-cfb'))
config['protocol'] = to_str(config.get('protocol', 'origin'))
config['protocol_param'] = to_str(config.get('protocol_param', ''))
config['obfs'] = to_str(config.get('obfs', 'plain'))
config['obfs_param'] = to_str(config.get('obfs_param', ''))
config['port_password'] = config.get('port_password', None)

9
shadowsocks/tcprelay.py

@ -115,7 +115,8 @@ class TCPRelayHandler(object):
server_info = obfs.server_info(server.obfs_data)
server_info.host = config['server']
server_info.port = server._listen_port
server_info.param = config['obfs_param']
server_info.protocol_param = ''
server_info.obfs_param = config['obfs_param']
server_info.iv = self._encryptor.cipher_iv
server_info.recv_iv = b''
server_info.key = self._encryptor.cipher_key
@ -127,7 +128,8 @@ class TCPRelayHandler(object):
server_info = obfs.server_info(server.protocol_data)
server_info.host = config['server']
server_info.port = server._listen_port
server_info.param = ''
server_info.protocol_param = config['protocol_param']
server_info.obfs_param = ''
server_info.iv = self._encryptor.cipher_iv
server_info.recv_iv = b''
server_info.key = self._encryptor.cipher_key
@ -343,11 +345,12 @@ class TCPRelayHandler(object):
return (host_post, 80)
def _handel_protocol_error(self, client_address, ogn_data):
#raise Exception('can not parse header')
logging.warn("Protocol ERROR, TCP ogn data %s from %s:%d" % (binascii.hexlify(ogn_data), client_address[0], client_address[1]))
self._encrypt_correct = False
#create redirect or disconnect by hash code
host, port = self._get_redirect_host(client_address, ogn_data)
if port == 0:
raise Exception('can not parse header')
data = b"\x03" + common.chr(len(host)) + common.to_bytes(host) + struct.pack('>H', port)
logging.warn("TCP data redir %s:%d %s" % (host, port, binascii.hexlify(data)))
return data + ogn_data

Loading…
Cancel
Save