Browse Source

fastopen

1.4
clowwindy 11 years ago
parent
commit
0b9ff0557f
  1. 8
      shadowsocks/local.py
  2. 4
      shadowsocks/server.py

8
shadowsocks/local.py

@ -202,9 +202,13 @@ class Socks5Server(SocketServer.StreamRequestHandler):
self.wfile.write(reply)
# reply immediately
aServer, aPort = self.getServer()
remote = socket.create_connection((aServer, aPort))
MSG_FASTOPEN = 0x20000000
remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# remote = socket.create_connection((aServer, aPort))
remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.send_encrypt(remote, addr_to_send)
data = self.encrypt(addr_to_send)
remote.sendto(data, MSG_FASTOPEN, (aServer, aPort))
# self.send_encrypt(remote, addr_to_send)
logging.info('connecting %s:%d' % (addr, port[0]))
except socket.error, e:
logging.warn(e)

4
shadowsocks/server.py

@ -65,6 +65,10 @@ def send_all(sock, data):
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
allow_reuse_address = True
def server_activate(self):
self.socket.setsockopt(socket.SOL_TCP, 23, 5)
self.socket.listen(self.request_queue_size)
class Socks5Server(SocketServer.StreamRequestHandler):
def handle_tcp(self, sock, remote):

Loading…
Cancel
Save