From 46d23bf0d4bfa1692d1400a68d147b425ccdcd6c Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 19 Jun 2014 09:20:04 +0800 Subject: [PATCH] more log --- shadowsocks/eventloop.py | 3 ++- shadowsocks/tcprelay.py | 6 +++--- shadowsocks/udprelay.py | 12 +++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/shadowsocks/eventloop.py b/shadowsocks/eventloop.py index e8af800..0b628e0 100644 --- a/shadowsocks/eventloop.py +++ b/shadowsocks/eventloop.py @@ -199,9 +199,10 @@ class EventLoop(object): except (OSError, IOError) as e: if errno_from_exception(e) == errno.EPIPE: # Happens when the client closes the connection + logging.error('poll:%s', e) continue else: - logging.error(e) + logging.error('poll:%s', e) import traceback traceback.print_exc() continue diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 81b9d92..285c166 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -589,9 +589,9 @@ class TCPRelay(object): def _handle_events(self, events): for sock, fd, event in events: - # if sock: - # logging.debug('fd %d %s', fd, - # eventloop.EVENT_NAMES.get(event, event)) + if sock: + logging.debug('fd %d %s', fd, + eventloop.EVENT_NAMES.get(event, event)) if sock == self._server_socket: if event & eventloop.POLL_ERR: # TODO diff --git a/shadowsocks/udprelay.py b/shadowsocks/udprelay.py index 5218feb..c7faeee 100644 --- a/shadowsocks/udprelay.py +++ b/shadowsocks/udprelay.py @@ -133,6 +133,8 @@ class UDPRelay(object): def _handle_server(self): server = self._server_socket data, r_addr = server.recvfrom(BUF_SIZE) + if not data: + logging.debug('UDP handle_server: data is empty') if self._is_local: frag = ord(data[2]) if frag != 0: @@ -141,9 +143,10 @@ class UDPRelay(object): else: data = data[3:] else: - # decrypt data data = encrypt.encrypt_all(self._password, self._method, 0, data) + # decrypt data if not data: + logging.debug('UDP handle_server: data is empty after decrypt') return header_result = parse_header(data) if header_result is None: @@ -191,6 +194,9 @@ class UDPRelay(object): def _handle_client(self, sock): data, r_addr = sock.recvfrom(BUF_SIZE) + if not data: + logging.debug('UDP handle_client: data is empty') + return if not self._is_local: addrlen = len(r_addr[0]) if addrlen > 255: @@ -235,8 +241,12 @@ class UDPRelay(object): def _handle_events(self, events): for sock, fd, event in events: if sock == self._server_socket: + if event & eventloop.POLL_ERR: + logging.error('UDP server_socket err') self._handle_server() elif sock and (fd in self._sockets): + if event & eventloop.POLL_ERR: + logging.error('UDP client_socket err') self._handle_client(sock) now = time.time() if now - self._last_time > 3.5: