From c6a879ddedef611ae81e755886262cd5c78815e0 Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Thu, 13 Dec 2018 00:22:34 +0800 Subject: [PATCH] kcp: add some default settings to kcp conn (to improve the speed) --- proxy/kcp/kcp.go | 20 +++++++++++++++++++- proxy/obfs/tls.go | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/proxy/kcp/kcp.go b/proxy/kcp/kcp.go index 209230f..e404cde 100644 --- a/proxy/kcp/kcp.go +++ b/proxy/kcp/kcp.go @@ -162,12 +162,19 @@ func (s *KCP) ListenAndServe() { log.F("[kcp] listening on %s", s.addr) for { - c, err := l.Accept() + c, err := l.AcceptKCP() if err != nil { log.F("[kcp] failed to accept: %v", err) continue } + c.SetStreamMode(true) + c.SetWriteDelay(false) + c.SetNoDelay(0, 30, 2, 1) + c.SetWindowSize(1024, 1024) + c.SetMtu(1350) + c.SetACKNoDelay(true) + go s.Serve(c) } } @@ -197,6 +204,17 @@ func (s *KCP) Dial(network, addr string) (net.Conn, error) { return nil, err } + c.SetStreamMode(true) + c.SetWriteDelay(false) + c.SetNoDelay(0, 30, 2, 1) + c.SetWindowSize(1024, 1024) + c.SetMtu(1350) + c.SetACKNoDelay(true) + + c.SetDSCP(0) + c.SetReadBuffer(4194304) + c.SetWriteBuffer(4194304) + return c, err } diff --git a/proxy/obfs/tls.go b/proxy/obfs/tls.go index 34dbda5..7756bd3 100644 --- a/proxy/obfs/tls.go +++ b/proxy/obfs/tls.go @@ -189,7 +189,7 @@ func clientHello() *bytes.Buffer { // https://github.com/shadowsocks/simple-obfs/blob/7659eeccf473aa41eb294e92c32f8f60a8747325/src/obfs_tls.c#L57 // Cipher Suites Length: 56 - buf.Write([]byte{0x00, 0x38}) + binary.Write(buf, binary.BigEndian, uint16(56)) // Cipher Suites (28 suites) buf.Write([]byte{ 0xc0, 0x2c, 0xc0, 0x30, 0x00, 0x9f, 0xcc, 0xa9, 0xcc, 0xa8, 0xcc, 0xaa, 0xc0, 0x2b, 0xc0, 0x2f,