add MYSQL_TRANSFER_MUL
add protocol_param (for auth_simple)
This commit is contained in:
parent
4894925cac
commit
b5da4bc86a
7 changed files with 42 additions and 16 deletions
|
@ -4,6 +4,7 @@ MYSQL_PORT = 3306
|
||||||
MYSQL_USER = 'ss'
|
MYSQL_USER = 'ss'
|
||||||
MYSQL_PASS = 'ss'
|
MYSQL_PASS = 'ss'
|
||||||
MYSQL_DB = 'shadowsocks'
|
MYSQL_DB = 'shadowsocks'
|
||||||
|
MYSQL_TRANSFER_MUL = 1.0
|
||||||
|
|
||||||
MANAGE_PASS = 'ss233333333'
|
MANAGE_PASS = 'ss233333333'
|
||||||
#if you want manage in other server you should set this value to global ip
|
#if you want manage in other server you should set this value to global ip
|
||||||
|
|
|
@ -37,14 +37,16 @@ class DbTransfer(object):
|
||||||
continue
|
continue
|
||||||
elif last_transfer[id][0] <= curr_transfer[id][0] and \
|
elif last_transfer[id][0] <= curr_transfer[id][0] and \
|
||||||
last_transfer[id][1] <= curr_transfer[id][1]:
|
last_transfer[id][1] <= curr_transfer[id][1]:
|
||||||
dt_transfer[id] = [curr_transfer[id][0] - last_transfer[id][0],
|
dt_transfer[id] = [int((curr_transfer[id][0] - last_transfer[id][0]) * Config.MYSQL_TRANSFER_MUL),
|
||||||
curr_transfer[id][1] - last_transfer[id][1]]
|
int((curr_transfer[id][1] - last_transfer[id][1]) * Config.MYSQL_TRANSFER_MUL)]
|
||||||
else:
|
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:
|
else:
|
||||||
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
|
if curr_transfer[id][0] == 0 and curr_transfer[id][1] == 0:
|
||||||
continue
|
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
|
self.last_get_transfer = curr_transfer
|
||||||
query_head = 'UPDATE user'
|
query_head = 'UPDATE user'
|
||||||
|
|
|
@ -127,13 +127,16 @@ class obfs_auth_data(object):
|
||||||
self.startup_time = int(time.time() - 30) & 0xFFFFFFFF
|
self.startup_time = int(time.time() - 30) & 0xFFFFFFFF
|
||||||
self.local_client_id = b''
|
self.local_client_id = b''
|
||||||
self.connection_id = 0
|
self.connection_id = 0
|
||||||
self.max_client = 16 # max active client count
|
self.set_max_client(16) # max active client count
|
||||||
self.max_buffer = max(self.max_client, 256) # max client id buffer size
|
|
||||||
|
|
||||||
def update(self, client_id, connection_id):
|
def update(self, client_id, connection_id):
|
||||||
if client_id in self.client_id:
|
if client_id in self.client_id:
|
||||||
self.client_id[client_id].update()
|
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):
|
def insert(self, client_id, connection_id):
|
||||||
if client_id not in self.client_id or not self.client_id[client_id].enable:
|
if client_id not in self.client_id or not self.client_id[client_id].enable:
|
||||||
active = 0
|
active = 0
|
||||||
|
@ -184,6 +187,13 @@ class auth_simple(verify_base):
|
||||||
def init_data(self):
|
def init_data(self):
|
||||||
return obfs_auth_data()
|
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):
|
def pack_data(self, buf):
|
||||||
if len(buf) == 0:
|
if len(buf) == 0:
|
||||||
return b''
|
return b''
|
||||||
|
|
|
@ -101,7 +101,7 @@ class http_simple(plain.plain):
|
||||||
if self.server_info.port != 80:
|
if self.server_info.port != 80:
|
||||||
port = b':' + common.to_bytes(str(self.server_info.port))
|
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"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"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"
|
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
|
self.has_sent_header = True
|
||||||
|
@ -171,8 +171,8 @@ class http_simple(plain.plain):
|
||||||
else:
|
else:
|
||||||
return (b'', True, False)
|
return (b'', True, False)
|
||||||
|
|
||||||
|
if b'\r\n\r\n' in buf:
|
||||||
datas = buf.split(b'\r\n\r\n', 1)
|
datas = buf.split(b'\r\n\r\n', 1)
|
||||||
if datas:
|
|
||||||
ret_buf = self.get_data_from_http_header(buf)
|
ret_buf = self.get_data_from_http_header(buf)
|
||||||
if len(datas) > 1:
|
if len(datas) > 1:
|
||||||
ret_buf += 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))
|
port = b':' + common.to_bytes(str(self.server_info.port))
|
||||||
self.has_sent_header = True
|
self.has_sent_header = True
|
||||||
http_head = b"GET / HTTP/1.1\r\n"
|
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"Connection: Upgrade, HTTP2-Settings\r\nUpgrade: h2c\r\n"
|
||||||
http_head += b"HTTP2-Settings: " + base64.urlsafe_b64encode(buf) + b"\r\n"
|
http_head += b"HTTP2-Settings: " + base64.urlsafe_b64encode(buf) + b"\r\n"
|
||||||
return http_head + b"\r\n"
|
return http_head + b"\r\n"
|
||||||
|
|
|
@ -69,6 +69,8 @@ def main():
|
||||||
del config['port_password']
|
del config['port_password']
|
||||||
for port, password_obfs in port_password.items():
|
for port, password_obfs in port_password.items():
|
||||||
protocol = config.get("protocol", 'origin')
|
protocol = config.get("protocol", 'origin')
|
||||||
|
protocol_param = config.get("protocol_param", '')
|
||||||
|
obfs = config.get("obfs", 'plain')
|
||||||
obfs_param = config.get("obfs_param", '')
|
obfs_param = config.get("obfs_param", '')
|
||||||
if type(password_obfs) == list:
|
if type(password_obfs) == list:
|
||||||
password = password_obfs[0]
|
password = password_obfs[0]
|
||||||
|
@ -80,7 +82,6 @@ def main():
|
||||||
obfs_param = password_obfs.get('obfs_param', '')
|
obfs_param = password_obfs.get('obfs_param', '')
|
||||||
else:
|
else:
|
||||||
password = password_obfs
|
password = password_obfs
|
||||||
obfs = config["obfs"]
|
|
||||||
a_config = config.copy()
|
a_config = config.copy()
|
||||||
ipv6_ok = False
|
ipv6_ok = False
|
||||||
logging.info("server start with protocol[%s] password [%s] method [%s] obfs [%s] obfs_param [%s]" %
|
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['server_port'] = int(port)
|
||||||
a_config['password'] = password
|
a_config['password'] = password
|
||||||
a_config['protocol'] = protocol
|
a_config['protocol'] = protocol
|
||||||
|
a_config['protocol_param'] = protocol_param
|
||||||
a_config['obfs'] = obfs
|
a_config['obfs'] = obfs
|
||||||
a_config['obfs_param'] = obfs_param
|
a_config['obfs_param'] = obfs_param
|
||||||
a_config['server'] = a_config['server_ipv6']
|
a_config['server'] = a_config['server_ipv6']
|
||||||
|
@ -109,6 +111,7 @@ def main():
|
||||||
a_config['server_port'] = int(port)
|
a_config['server_port'] = int(port)
|
||||||
a_config['password'] = password
|
a_config['password'] = password
|
||||||
a_config['protocol'] = protocol
|
a_config['protocol'] = protocol
|
||||||
|
a_config['protocol_param'] = protocol_param
|
||||||
a_config['obfs'] = obfs
|
a_config['obfs'] = obfs
|
||||||
a_config['obfs_param'] = obfs_param
|
a_config['obfs_param'] = obfs_param
|
||||||
logging.info("starting server at %s:%d" %
|
logging.info("starting server at %s:%d" %
|
||||||
|
|
|
@ -130,11 +130,11 @@ def get_config(is_local):
|
||||||
logging.basicConfig(level=logging.INFO,
|
logging.basicConfig(level=logging.INFO,
|
||||||
format='%(levelname)-s: %(message)s')
|
format='%(levelname)-s: %(message)s')
|
||||||
if is_local:
|
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=',
|
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'user=',
|
||||||
'version']
|
'version']
|
||||||
else:
|
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=',
|
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
|
||||||
'forbidden-ip=', 'user=', 'manager-address=', 'version']
|
'forbidden-ip=', 'user=', 'manager-address=', 'version']
|
||||||
try:
|
try:
|
||||||
|
@ -168,8 +168,14 @@ def get_config(is_local):
|
||||||
config['server'] = to_str(value)
|
config['server'] = to_str(value)
|
||||||
elif key == '-m':
|
elif key == '-m':
|
||||||
config['method'] = to_str(value)
|
config['method'] = to_str(value)
|
||||||
|
elif key == '-P':
|
||||||
|
config['protocol'] = to_str(value)
|
||||||
elif key == '-o':
|
elif key == '-o':
|
||||||
config['obfs'] = to_str(value)
|
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':
|
elif key == '-b':
|
||||||
config['local_address'] = to_str(value)
|
config['local_address'] = to_str(value)
|
||||||
elif key == '-v':
|
elif key == '-v':
|
||||||
|
@ -219,6 +225,7 @@ def get_config(is_local):
|
||||||
config['password'] = to_bytes(config.get('password', b''))
|
config['password'] = to_bytes(config.get('password', b''))
|
||||||
config['method'] = to_str(config.get('method', 'aes-256-cfb'))
|
config['method'] = to_str(config.get('method', 'aes-256-cfb'))
|
||||||
config['protocol'] = to_str(config.get('protocol', 'origin'))
|
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'] = to_str(config.get('obfs', 'plain'))
|
||||||
config['obfs_param'] = to_str(config.get('obfs_param', ''))
|
config['obfs_param'] = to_str(config.get('obfs_param', ''))
|
||||||
config['port_password'] = config.get('port_password', None)
|
config['port_password'] = config.get('port_password', None)
|
||||||
|
|
|
@ -115,7 +115,8 @@ class TCPRelayHandler(object):
|
||||||
server_info = obfs.server_info(server.obfs_data)
|
server_info = obfs.server_info(server.obfs_data)
|
||||||
server_info.host = config['server']
|
server_info.host = config['server']
|
||||||
server_info.port = server._listen_port
|
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.iv = self._encryptor.cipher_iv
|
||||||
server_info.recv_iv = b''
|
server_info.recv_iv = b''
|
||||||
server_info.key = self._encryptor.cipher_key
|
server_info.key = self._encryptor.cipher_key
|
||||||
|
@ -127,7 +128,8 @@ class TCPRelayHandler(object):
|
||||||
server_info = obfs.server_info(server.protocol_data)
|
server_info = obfs.server_info(server.protocol_data)
|
||||||
server_info.host = config['server']
|
server_info.host = config['server']
|
||||||
server_info.port = server._listen_port
|
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.iv = self._encryptor.cipher_iv
|
||||||
server_info.recv_iv = b''
|
server_info.recv_iv = b''
|
||||||
server_info.key = self._encryptor.cipher_key
|
server_info.key = self._encryptor.cipher_key
|
||||||
|
@ -343,11 +345,12 @@ class TCPRelayHandler(object):
|
||||||
return (host_post, 80)
|
return (host_post, 80)
|
||||||
|
|
||||||
def _handel_protocol_error(self, client_address, ogn_data):
|
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]))
|
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
|
self._encrypt_correct = False
|
||||||
#create redirect or disconnect by hash code
|
#create redirect or disconnect by hash code
|
||||||
host, port = self._get_redirect_host(client_address, ogn_data)
|
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)
|
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)))
|
logging.warn("TCP data redir %s:%d %s" % (host, port, binascii.hexlify(data)))
|
||||||
return data + ogn_data
|
return data + ogn_data
|
||||||
|
|
Loading…
Add table
Reference in a new issue