From 928c26e4f2d3bff7a4ff750f472a8959efc05be1 Mon Sep 17 00:00:00 2001 From: breakwa11 Date: Sat, 15 Aug 2015 12:47:14 +0800 Subject: [PATCH] fix some exceptions --- shadowsocks/encrypt.py | 6 +++++- shadowsocks/udprelay.py | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/shadowsocks/encrypt.py b/shadowsocks/encrypt.py index 834b18c..5d11138 100644 --- a/shadowsocks/encrypt.py +++ b/shadowsocks/encrypt.py @@ -21,6 +21,7 @@ import os import sys import hashlib import logging +import random from shadowsocks import common from shadowsocks.crypto import rc4_md5, openssl, sodium, table @@ -34,7 +35,10 @@ method_supported.update(table.ciphers) def random_string(length): - return os.urandom(length) + try: + return os.urandom(length) + except (AttributeError, NotImplementedError): + return ''.join(chr(random.randrange(255)) for _ in range(length)) cached_keys = {} diff --git a/shadowsocks/udprelay.py b/shadowsocks/udprelay.py index 4c5ff21..3ea9b6d 100644 --- a/shadowsocks/udprelay.py +++ b/shadowsocks/udprelay.py @@ -1036,8 +1036,11 @@ class UDPRelay(object): self.write_to_server_socket(data_to_send, r_addr) elif data[0] > CMD_CONNECT_REMOTE and data[0] <= CMD_DISCONNECT: if data[1] in self._reqid_to_hd: - self.update_activity(self._reqid_to_hd[data[1]]) - self._reqid_to_hd[data[1]].handle_client(r_addr, *data) + if type(self._reqid_to_hd[data[1]]) is tuple: + pass + else: + self.update_activity(self._reqid_to_hd[data[1]]) + self._reqid_to_hd[data[1]].handle_client(r_addr, *data) else: # disconnect rsp_data = self._pack_rsp_data(CMD_DISCONNECT, data[1], RSP_STATE_EMPTY)