From 45340b28450a423dcb2757b636d5fb3a2b36790b Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Wed, 13 Apr 2022 21:06:29 +0800 Subject: [PATCH] update kcp --- README.md | 2 ++ README_en.md | 1 + kcp.go | 38 +++++++++++++++++++++++++++++++++----- snap/snapcraft.yaml | 4 +++- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 88aef0e..1d111eb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ GO Simple Tunnel [![codecov](https://codecov.io/gh/ginuerzh/gost/branch/master/graphs/badge.svg)](https://codecov.io/gh/ginuerzh/gost/branch/master) [![GitHub release](https://img.shields.io/github/release/ginuerzh/gost.svg)](https://github.com/ginuerzh/gost/releases/latest) [![Docker](https://img.shields.io/docker/pulls/ginuerzh/gost.svg)](https://hub.docker.com/r/ginuerzh/gost/) +[![gost](https://snapcraft.io/gost/badge.svg)](https://snapcraft.io/gost) [English README](README_en.md) @@ -68,6 +69,7 @@ brew install gost #### Ubuntu商店 + ```bash sudo snap install core sudo snap install gost diff --git a/README_en.md b/README_en.md index 2cdce87..3fe6b9a 100644 --- a/README_en.md +++ b/README_en.md @@ -8,6 +8,7 @@ gost - GO Simple Tunnel [![codecov](https://codecov.io/gh/ginuerzh/gost/branch/master/graphs/badge.svg)](https://codecov.io/gh/ginuerzh/gost/branch/master) [![GitHub release](https://img.shields.io/github/release/ginuerzh/gost.svg)](https://github.com/ginuerzh/gost/releases/latest) [![Docker](https://img.shields.io/docker/pulls/ginuerzh/gost.svg)](https://hub.docker.com/r/ginuerzh/gost/) +[![gost](https://snapcraft.io/gost/badge.svg)](https://snapcraft.io/gost) Features ------ diff --git a/kcp.go b/kcp.go index 7566cf7..573c91f 100644 --- a/kcp.go +++ b/kcp.go @@ -43,6 +43,9 @@ type KCPConfig struct { Resend int `json:"resend"` NoCongestion int `json:"nc"` SockBuf int `json:"sockbuf"` + SmuxBuf int `json:"smuxbuf"` + StreamBuf int `json:"streambuf"` + SmuxVer int `json:"smuxver"` KeepAlive int `json:"keepalive"` SnmpLog string `json:"snmplog"` SnmpPeriod int `json:"snmpperiod"` @@ -62,6 +65,16 @@ func (c *KCPConfig) Init() { case "fast3": c.NoDelay, c.Interval, c.Resend, c.NoCongestion = 1, 10, 2, 1 } + if c.SmuxVer <= 0 { + c.SmuxVer = 1 + } + if c.SmuxBuf <= 0 { + c.SmuxBuf = c.SockBuf + } + if c.StreamBuf <= 0 { + c.StreamBuf = c.SockBuf / 2 + } + log.Logf("%#v", c) } var ( @@ -83,6 +96,9 @@ var ( Resend: 0, NoCongestion: 0, SockBuf: 4194304, + SmuxVer: 1, + SmuxBuf: 4194304, + StreamBuf: 2097152, KeepAlive: 10, SnmpLog: "", SnmpPeriod: 60, @@ -231,8 +247,14 @@ func (tr *kcpTransporter) initSession(addr string, conn net.Conn, config *KCPCon // stream multiplex smuxConfig := smux.DefaultConfig() - smuxConfig.MaxReceiveBuffer = config.SockBuf + smuxConfig.Version = config.SmuxVer + smuxConfig.MaxReceiveBuffer = config.SmuxBuf + smuxConfig.MaxStreamBuffer = config.StreamBuf smuxConfig.KeepAliveInterval = time.Duration(config.KeepAlive) * time.Second + if err := smux.VerifyConfig(smuxConfig); err != nil { + return nil, err + } + var cc net.Conn = kcpconn if !config.NoComp { cc = newCompStreamConn(kcpconn) @@ -332,7 +354,9 @@ func (l *kcpListener) listenLoop() { func (l *kcpListener) mux(conn net.Conn) { smuxConfig := smux.DefaultConfig() - smuxConfig.MaxReceiveBuffer = l.config.SockBuf + smuxConfig.Version = l.config.SmuxVer + smuxConfig.MaxReceiveBuffer = l.config.SmuxBuf + smuxConfig.MaxStreamBuffer = l.config.StreamBuf smuxConfig.KeepAliveInterval = time.Duration(l.config.KeepAlive) * time.Second log.Logf("[kcp] %s - %s", conn.RemoteAddr(), l.Addr()) @@ -473,9 +497,13 @@ func (c *compStreamConn) Read(b []byte) (n int, err error) { } func (c *compStreamConn) Write(b []byte) (n int, err error) { - n, err = c.w.Write(b) - err = c.w.Flush() - return n, err + if _, err = c.w.Write(b); err != nil { + return 0, err + } + if err = c.w.Flush(); err != nil { + return 0, err + } + return len(b), err } func (c *compStreamConn) Close() error { diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 958e1c0..ba6209f 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -5,8 +5,10 @@ summary: A simple security tunnel written in golang description: | Project: https://github.com/ginuerzh/gost Wiki: https://v2.gost.run - icon: gost.png +website: https://v2.gost.run + + confinement: strict grade: stable