mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 08:31:30 +00:00
Fix websocket headroom
This commit is contained in:
parent
89ff9f8368
commit
a01bb569d1
|
@ -146,6 +146,8 @@ func newUTLSClient(router adapter.Router, serverAddress string, options option.O
|
||||||
id = utls.HelloAndroid_11_OkHttp
|
id = utls.HelloAndroid_11_OkHttp
|
||||||
case "random":
|
case "random":
|
||||||
id = utls.HelloRandomized
|
id = utls.HelloRandomized
|
||||||
|
default:
|
||||||
|
return nil, E.New("unknown uTLS fingerprint: ", options.UTLS.Fingerprint)
|
||||||
}
|
}
|
||||||
return &utlsClientConfig{&tlsConfig, id}, nil
|
return &utlsClientConfig{&tlsConfig, id}, nil
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -23,7 +23,7 @@ require (
|
||||||
github.com/pires/go-proxyproto v0.6.2
|
github.com/pires/go-proxyproto v0.6.2
|
||||||
github.com/refraction-networking/utls v1.1.2
|
github.com/refraction-networking/utls v1.1.2
|
||||||
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb
|
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb
|
||||||
github.com/sagernet/sing v0.0.0-20221006081821-c4e9bf11fa00
|
github.com/sagernet/sing v0.0.0-20221008120626-60a9910eefe4
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220929010544-ee843807aae3
|
github.com/sagernet/sing-dns v0.0.0-20220929010544-ee843807aae3
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6
|
||||||
github.com/sagernet/sing-tun v0.0.0-20221005115555-9a556307f6a3
|
github.com/sagernet/sing-tun v0.0.0-20221005115555-9a556307f6a3
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -145,8 +145,8 @@ github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb h1:wc0yQ+SBn4TaTY
|
||||||
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb/go.mod h1:MIccjRKnPTjWwAOpl+AUGWOkzyTd9tERytudxu+1ra4=
|
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb/go.mod h1:MIccjRKnPTjWwAOpl+AUGWOkzyTd9tERytudxu+1ra4=
|
||||||
github.com/sagernet/sing v0.0.0-20220812082120-05f9836bff8f/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
github.com/sagernet/sing v0.0.0-20220812082120-05f9836bff8f/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||||
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||||
github.com/sagernet/sing v0.0.0-20221006081821-c4e9bf11fa00 h1:UkgEDnH3L9eBxob+3AbE9wM4mjFnRLnaPjfLSNe+C74=
|
github.com/sagernet/sing v0.0.0-20221008120626-60a9910eefe4 h1:LO7xMvMGhYmjQg2vjhTzsODyzs9/WLYu5Per+/8jIeo=
|
||||||
github.com/sagernet/sing v0.0.0-20221006081821-c4e9bf11fa00/go.mod h1:zvgDYKI+vCAW9RyfyrKTgleI+DOa8lzHMPC7VZo3OL4=
|
github.com/sagernet/sing v0.0.0-20221008120626-60a9910eefe4/go.mod h1:zvgDYKI+vCAW9RyfyrKTgleI+DOa8lzHMPC7VZo3OL4=
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220929010544-ee843807aae3 h1:AEdyJxEDFq38z0pBX/0MpikQapGMIch+1ADe9k1bJqU=
|
github.com/sagernet/sing-dns v0.0.0-20220929010544-ee843807aae3 h1:AEdyJxEDFq38z0pBX/0MpikQapGMIch+1ADe9k1bJqU=
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220929010544-ee843807aae3/go.mod h1:SrvWLfOSlnFmH32CWXicfilAGgIXR0VjrH6yRbuXYww=
|
github.com/sagernet/sing-dns v0.0.0-20220929010544-ee843807aae3/go.mod h1:SrvWLfOSlnFmH32CWXicfilAGgIXR0VjrH6yRbuXYww=
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6 h1:JJfDeYYhWunvtxsU/mOVNTmFQmnzGx9dY034qG6G3g4=
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6 h1:JJfDeYYhWunvtxsU/mOVNTmFQmnzGx9dY034qG6G3g4=
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
|
"github.com/sagernet/sing/common"
|
||||||
"github.com/sagernet/sing/common/buf"
|
"github.com/sagernet/sing/common/buf"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
"github.com/sagernet/websocket"
|
"github.com/sagernet/websocket"
|
||||||
|
@ -68,8 +69,12 @@ func (c *WebsocketConn) SetDeadline(t time.Time) error {
|
||||||
return os.ErrInvalid
|
return os.ErrInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WebsocketConn) FrontHeadroom() int {
|
func (c *WebsocketConn) Upstream() any {
|
||||||
return frontHeadroom
|
return c.Conn.NetConn()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *WebsocketConn) UpstreamWriter() any {
|
||||||
|
return c.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
type EarlyWebsocketConn struct {
|
type EarlyWebsocketConn struct {
|
||||||
|
@ -210,8 +215,12 @@ func (c *EarlyWebsocketConn) SetWriteDeadline(t time.Time) error {
|
||||||
return c.conn.SetWriteDeadline(t)
|
return c.conn.SetWriteDeadline(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EarlyWebsocketConn) FrontHeadroom() int {
|
func (c *EarlyWebsocketConn) Upstream() any {
|
||||||
return frontHeadroom
|
return common.PtrOrNil(c.conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *EarlyWebsocketConn) LazyHeadroom() bool {
|
||||||
|
return c.conn == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrapError(err error) error {
|
func wrapError(err error) error {
|
||||||
|
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"github.com/sagernet/websocket"
|
"github.com/sagernet/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
const frontHeadroom = 14
|
|
||||||
|
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
*websocket.Conn
|
*websocket.Conn
|
||||||
writer N.ExtendedWriter
|
writer N.ExtendedWriter
|
||||||
|
@ -85,5 +83,5 @@ func (w *Writer) Upstream() any {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Writer) FrontHeadroom() int {
|
func (w *Writer) FrontHeadroom() int {
|
||||||
return frontHeadroom
|
return 14
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue