This commit is contained in:
clowwindy 2014-08-27 00:17:26 +08:00
parent b468476c9c
commit 972bf22e6d
8 changed files with 19 additions and 16 deletions

View file

@ -403,8 +403,8 @@ class DNSResolver(object):
self._request_id = 1
req = build_request(hostname, qtype, self._request_id)
for server in self._servers:
logging.debug('resolving %s with type %d using server %s', hostname,
qtype, server)
logging.debug('resolving %s with type %d using server %s',
hostname, qtype, server)
self._sock.sendto(req, (server, 53))
def resolve(self, hostname, callback):

View file

@ -126,7 +126,8 @@ def parse_header(data):
else:
logging.warn('header is too short')
else:
logging.warn('unsupported addrtype %d, maybe wrong password' % addrtype)
logging.warn('unsupported addrtype %d, maybe wrong password' %
addrtype)
if dest_addr is None:
return None
return addrtype, dest_addr, dest_port, header_length

View file

@ -154,7 +154,8 @@ class Encryptor(object):
iv = iv_
iv = iv[:m[1]]
if op == 1:
self.cipher_iv = iv[:m[1]] # this iv is for cipher not decipher
# this iv is for cipher not decipher
self.cipher_iv = iv[:m[1]]
if method != 'salsa20-ctr':
import M2Crypto.EVP
return M2Crypto.EVP.Cipher(method.replace('-', '_'), key, iv,

View file

@ -67,7 +67,8 @@ class Salsa20Cipher(object):
def _next_stream(self):
self._nonce &= 0xFFFFFFFFFFFFFFFF
self._stream = salsa20.Salsa20_keystream(BLOCK_SIZE,
struct.pack('<Q', self._nonce),
struct.pack('<Q',
self._nonce),
self._key)
self._nonce += 1
@ -129,4 +130,4 @@ def test():
if __name__ == '__main__':
test()
test()

View file

@ -201,8 +201,9 @@ class TCPRelayHandler(object):
self._config['fast_open']:
try:
self._fastopen_connected = True
remote_sock = self._create_remote_socket(self._chosen_server[0],
self._chosen_server[1])
remote_sock = \
self._create_remote_socket(self._chosen_server[0],
self._chosen_server[1])
self._loop.add(remote_sock, eventloop.POLL_ERR)
data = ''.join(self._data_to_write_to_local)
l = len(data)
@ -497,8 +498,8 @@ class TCPRelay(object):
self._timeout = config['timeout']
self._timeouts = [] # a list for all the handlers
self._timeout_offset = 0 # last checked position for timeout
# we trim the timeouts once a while
# we trim the timeouts once a while
self._timeout_offset = 0 # last checked position for timeout
self._handler_to_timeouts = {} # key: handler value: index in timeouts
if is_local:
@ -606,9 +607,9 @@ class TCPRelay(object):
try:
logging.debug('accept')
conn = self._server_socket.accept()
TCPRelayHandler(self, self._fd_to_handlers, self._eventloop,
conn[0], self._config, self._dns_resolver,
self._is_local)
TCPRelayHandler(self, self._fd_to_handlers,
self._eventloop, conn[0], self._config,
self._dns_resolver, self._is_local)
except (OSError, IOError) as e:
error_no = eventloop.errno_from_exception(e)
if error_no in (errno.EAGAIN, errno.EINPROGRESS,

View file

@ -275,4 +275,4 @@ def _decode_dict(data):
elif isinstance(value, dict):
value = _decode_dict(value)
rv[key] = value
return rv
return rv

View file

@ -29,7 +29,7 @@ try:
r, w, e = select.select(fdset, [], fdset)
if e:
break
for fd in r:
line = fd.readline()
sys.stdout.write(line)

View file

@ -10,4 +10,3 @@ for line in sys.stdin:
if 'HTTP/1.1 ' in line:
diff = time.time() - before
print 'headline %dms' % (diff * 1000)