Skip to content

Commit bbfd632

Browse files
committed
fix bugs, rename start script
1 parent f23314d commit bbfd632

File tree

17 files changed

+93
-46
lines changed

17 files changed

+93
-46
lines changed

code/default/gae_proxy/local/check_ip.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ def test_gae_ip2(ip, appid="xxnet-1", use_openssl=True):
212212
return False
213213

214214
if not hasattr(ssl_sock._connection, "protos"):
215-
#xlog.warn("ip:%s not support http/2", ip)
215+
if __name__ == "__main__":
216+
xlog.warn("ip:%s not support http/2", ip)
217+
216218
try:
217219
if not check_goagent(ssl_sock, appid):
218220
return False
@@ -230,7 +232,13 @@ def test_gae_ip2(ip, appid="xxnet-1", use_openssl=True):
230232
#xlog.exception("gae %r", e)
231233
xlog.debug("ip:%s http/1.1:%r", ip, e )
232234
return False
233-
response = conn.get_response()
235+
try:
236+
response = conn.get_response()
237+
except Exception as e:
238+
if __name__ == "__main__":
239+
xlog.exception("http2 get response fail:%r", e)
240+
return False
241+
234242
xlog.debug("ip:%s http/2", ip)
235243

236244
if response.status == 404:

code/default/gae_proxy/local/connect_manager.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ def connect_process(self):
334334
ssl_sock = self._create_ssl_connection( (ip_str, port) )
335335
if ssl_sock:
336336
ssl_sock.last_use_time = time.time()
337-
self.new_conn_pool.put((ssl_sock.handshake_time, ssl_sock))
337+
338+
if self.new_conn_pool.qsize() >= self.connection_pool_max_num and self.ssl_timeout_cb:
339+
self.ssl_timeout_cb(ssl_sock)
340+
else:
341+
self.new_conn_pool.put((ssl_sock.handshake_time, ssl_sock))
338342
finally:
339343
self.thread_num_lock.acquire()
340344
self.thread_num -= 1
@@ -375,7 +379,7 @@ def connect_thread(self, sleep_time=0):
375379
ssl_sock = self._create_ssl_connection( (ip_str, port) )
376380
if ssl_sock:
377381
ssl_sock.last_use_time = time.time()
378-
if self.new_conn_pool.qsize() > self.connection_pool_max_num and self.ssl_timeout_cb:
382+
if self.new_conn_pool.qsize() >= self.connection_pool_max_num and self.ssl_timeout_cb:
379383
self.ssl_timeout_cb(ssl_sock)
380384
else:
381385
self.new_conn_pool.put((ssl_sock.handshake_time, ssl_sock))

code/default/gae_proxy/local/http1.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@ def work_loop(self):
3232
last_ssl_active_time = self.ssl_sock.create_time
3333
last_request_time = time.time()
3434
while connect_control.keep_running and self.keep_running:
35-
time_to_ping = min(0, 50 - (time.time() - last_ssl_active_time))
35+
time_to_ping = min(0, 55 - (time.time() - last_ssl_active_time))
3636
try:
3737
task = self.task_queue.get(True, timeout=time_to_ping)
3838
if not task:
3939
# None task to exit
4040
return
4141
except:
42-
if time.time() - last_request_time > 4 * 60:
43-
self.close("idle 4 mins")
42+
if time.time() - last_request_time > 2 * 60:
43+
self.close("idle 2 mins")
4444
return
4545

4646
last_ssl_active_time = time.time()
4747
if not self.head_request():
48-
self.close("keep alive")
48+
google_ip.report_connect_fail(self.ssl_sock.ip, force_remove=True)
49+
# now many gvs don't support gae
50+
self.close("keep alive, maybe not support")
4951
return
5052
else:
5153
continue

code/default/gae_proxy/local/http2_connection.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ def send_loop(self):
168168
except socket.error as e:
169169
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
170170
xlog.warn("%s http2 send fail:%r", self.ip, e)
171-
self.close("send fail")
171+
else:
172+
xlog.exceptiong("send error:%r", e)
173+
174+
self.close("send fail:%r", e)
172175

173176
def recv_loop(self):
174177
while connect_control.keep_running and self.keep_running:

code/default/gae_proxy/local/http_dispatcher.py

+20
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,39 @@ def on_ssl_created_cb(self, ssl_sock):
102102
self.workers.append(worker)
103103
return worker
104104

105+
def create_worker_thread(self):
106+
ssl_sock = https_manager.get_ssl_connection()
107+
if not ssl_sock:
108+
xlog.warn("create_worker_thread get ssl_sock fail")
109+
110+
self.on_ssl_created_cb(ssl_sock)
111+
112+
def create_more_worker(self):
113+
threading.Thread(target=self.create_worker_thread).start()
114+
105115
def get_worker(self):
106116
best_rtt = 9999
107117
best_worker = None
118+
idle_num = 0
108119
for worker in self.workers:
109120
if not worker.accept_task:
110121
continue
111122

123+
if worker.version == "1.1":
124+
idle_num += 1
125+
else:
126+
if len(worker.streams) == 0:
127+
idle_num += 1
128+
112129
rtt = worker.get_rtt_rate()
113130

114131
if rtt < best_rtt:
115132
best_rtt = rtt
116133
best_worker = worker
117134

135+
if idle_num == 0:
136+
self.create_more_worker()
137+
118138
if best_worker:
119139
return best_worker
120140

code/default/gae_proxy/local/openssl_wrap.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __getattr__(self, attr):
5151
if attr not in ('_context', '_sock', '_connection', '_makefile_refs'):
5252
return getattr(self._connection, attr)
5353

54-
def __iowait(self, io_func, *args, **kwargs):
54+
def __iowait2(self, io_func, *args, **kwargs):
5555
timeout = self._sock.gettimeout() or 0.1
5656
fd = self._sock.fileno()
5757
time_start = time.time()
@@ -78,6 +78,30 @@ def __iowait(self, io_func, *args, **kwargs):
7878
#xlog.exception("e:%r", e)
7979
raise e
8080

81+
def __iowait(self, io_func, *args, **kwargs):
82+
timeout = self._sock.gettimeout() or 0.1
83+
fd = self._sock.fileno()
84+
time_start = time.time()
85+
while True:
86+
try:
87+
return io_func(*args, **kwargs)
88+
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError):
89+
sys.exc_clear()
90+
_, _, errors = select.select([fd], [], [fd], timeout)
91+
if errors:
92+
break
93+
time_now = time.time()
94+
if time_now - time_start > timeout:
95+
break
96+
except OpenSSL.SSL.WantWriteError:
97+
sys.exc_clear()
98+
_, _, errors = select.select([], [fd], [fd], timeout)
99+
if errors:
100+
break
101+
time_now = time.time()
102+
if time_now - time_start > timeout:
103+
break
104+
81105
def accept(self):
82106
sock, addr = self._sock.accept()
83107
client = OpenSSL.SSL.Connection(sock._context, sock)
@@ -221,20 +245,6 @@ def context_builder(ca_certs=None, cipher_suites=None):
221245
#
222246
if not cipher_suites:
223247
cipher_suites = ('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)
224-
"""
225-
cipher_suites = (
226-
"DHE-RSA-AES256-SHA256",
227-
"DHE-RSA-AES256-SHA",
228-
"DHE-RSA-AES128-SHA",
229-
"ECDHE-ECDSA-AES256-SHA",
230-
"ECDHE-ECDSA-AES128-SHA",
231-
"ECDHE-RSA-AES128-SHA",
232-
"ECDHE-ECDSA-RC4-SHA",
233-
"AES256-SHA",
234-
"AES128-SHA",
235-
"RC4-MD5",
236-
"DES-CBC3-SHA"
237-
)"""
238248

239249
protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version)
240250
ssl_context = OpenSSL.SSL.Context(protocol_version)

code/default/gae_proxy/local/proxy.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ record_ip_history = 0
9999

100100
[connect_manager]
101101
https_max_connect_thread = 20
102-
https_new_connect_num = 10
102+
https_new_connect_num = 1
103103

104104
;0 means don't keep new ssl link
105105
https_connection_pool_min = 0
106106

107107
; if exceed max, put ssl to worker.
108-
https_connection_pool_max = 5
108+
https_connection_pool_max = 3
109109

110110
; keep connection pool until no active request timeout
111111
keep_active_timeout = 600

code/default/launcher/autorun.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
current_path = os.path.dirname(os.path.abspath(__file__))
1111
root_path = os.path.abspath( os.path.join(current_path, os.pardir))
12+
top_path = os.path.abspath( os.path.join(root_path, os.pardir, os.pardir))
1213

1314
if sys.platform == 'win32':
1415
import _winreg
@@ -44,8 +45,7 @@ def remove(name):
4445
_winreg.DeleteValue(key, name)
4546
_winreg.CloseKey(key)
4647

47-
run_cmd = "\"" + os.path.abspath( os.path.join(root_path, "python27", "1.0", "pythonw.exe")) + "\" \"" +\
48-
os.path.abspath( os.path.join(root_path, "launcher", "start.py")) + "\""
48+
run_cmd = "\"" + os.path.join(top_path, "start.vbs") + "\""
4949
elif sys.platform.startswith('linux'):
5050
_xdg_config_home = os.environ.get("XDG_CONFIG_HOME", "~/.config")
5151
home_config_path = os.path.expanduser(_xdg_config_home)
@@ -86,7 +86,7 @@ def remove(name):
8686
if(exists(name)):
8787
os.unlink(getfilename(name))
8888

89-
run_cmd = os.path.abspath( os.path.join(root_path, os.pardir, os.pardir, "xxnet"))
89+
run_cmd = os.path.join(top_path, "start")
9090
elif sys.platform == 'darwin':
9191
plist_template = """<?xml version="1.0" encoding="UTF-8"?>
9292
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@@ -100,7 +100,6 @@ def remove(name):
100100
101101
<key>ProgramArguments</key>
102102
<array>
103-
<string>/usr/bin/python2.7</string>
104103
<string>%s</string>
105104
</array>
106105
@@ -114,7 +113,7 @@ def remove(name):
114113
</dict>
115114
</plist>"""
116115

117-
run_cmd = os.path.abspath( os.path.join(root_path, "launcher", "start.py"))
116+
run_cmd = os.path.join(top_path, "start")
118117
from os.path import expanduser
119118
home = expanduser("~")
120119
launch_path = os.path.join(home, "Library/LaunchAgents")

code/default/launcher/create_shortcut.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
function CreateShortcut()
33
{
44
wsh = new ActiveXObject('WScript.Shell');
5-
target_path = '"' + wsh.CurrentDirectory + '\\..\\python27\\1.0\\pythonw.exe"';
5+
target_path = '"' + wsh.CurrentDirectory + '\\..\\..\\..\\start.vbs"';
66
icon_path = wsh.CurrentDirectory + '\\web_ui\\favicon.ico';
77

88

99
link = wsh.CreateShortcut(wsh.SpecialFolders("Desktop") + '\\XX-Net.lnk');
1010
link.TargetPath = target_path;
11-
link.Arguments = '"' + wsh.CurrentDirectory + '\\start.py"';
11+
link.Arguments = '"'"';
1212
link.WindowStyle = 7;
1313
link.IconLocation = icon_path;
1414
link.Description = 'XX-Net';

code/default/launcher/post_update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def run(last_run_version):
3535
if sys.platform != 'win32' and filename == 'xxnet':
3636
st = os.stat(filepath)
3737
os.chmod(filepath, st.st_mode | stat.S_IEXEC)
38-
if not filename.startswith('.') and filename not in ['README.md', 'xxnet', 'xxnet.bat', 'xxnet.vbs']:
38+
if not filename.startswith('.') and filename not in ['README.md', 'start', 'start.bat', 'start.vbs']:
3939
os.remove(filepath)
4040
else:
4141
if not filename.startswith('.') and filename not in ['code', 'data']:

code/default/launcher/update_from_github.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ def restart_xxnet(version):
248248
start_script = os.path.join(top_path, "code", version, "launcher", "start.py")
249249

250250
subprocess.Popen([sys.executable, start_script])
251-
time.sleep(10)
252-
os._exit(0)
251+
time.sleep(20)
252+
#os._exit(0)
253253

254254

255255
def update_version(version):

code/default/python27/1.0/lib/noarch/hyper/common/bufsocket.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,20 @@ def send(self, buf, flush=True):
107107
self.send_buffer.append(buf)
108108

109109
if len(self.send_buffer) > 1300:
110-
data = self.send_buffer.get_string()
111-
self.send_buffer.reset()
112-
return self._sck.send(data)
110+
self.flush()
113111

114112
def flush(self):
115113
if len(self.send_buffer):
116114
data = self.send_buffer.get_string()
117115
logger.debug("buffer socket flush:%d", len(data))
118116
self.send_buffer.reset()
119-
sended = self._sck.send(data)
120-
if sended != len(data):
121-
raise Exception("send fail")
117+
118+
data_len = len(data)
119+
start = 0
120+
while start < data_len:
121+
send_size = min(data_len - start, 65535)
122+
sended = self._sck.send(data[start:start+send_size])
123+
start += sended
122124

123125
@property
124126
def _remaining_capacity(self):

code/default/python27/1.0/lib/noarch/hyper/packages/hyperframe/frame.py

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def __init__(self, stream_id, pad_length=0, **kwargs):
130130

131131
self.pad_length = pad_length
132132

133-
134133
def serialize_padding_data(self):
135134
if 'PADDED' in self.flags:
136135
return struct.pack('!B', self.pad_length)

xxnet start

File renamed without changes.

start.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SET PYTHONPATH=
2+
"%~dp0%start.vbs" console
3+

xxnet.vbs start.vbs

File renamed without changes.

xxnet.bat

-3
This file was deleted.

0 commit comments

Comments
 (0)