mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
Fix copy with src buffer to headroom writer
This commit is contained in:
parent
2ce09b6ffd
commit
2d3d46eb34
|
@ -323,6 +323,10 @@ func (c *ClientPacketConn) WriteBuffer(buffer *buf.Buffer) error {
|
|||
return c.ExtendedConn.WriteBuffer(buffer)
|
||||
}
|
||||
|
||||
func (c *ClientPacketConn) Headroom() int {
|
||||
return 2
|
||||
}
|
||||
|
||||
func (c *ClientPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
||||
return c.WriteBuffer(buffer)
|
||||
}
|
||||
|
@ -471,6 +475,10 @@ func (c *ClientPacketAddrConn) LocalAddr() net.Addr {
|
|||
return c.ExtendedConn.LocalAddr()
|
||||
}
|
||||
|
||||
func (c *ClientPacketAddrConn) Headroom() int {
|
||||
return 2 + M.MaxSocksaddrLength
|
||||
}
|
||||
|
||||
func (c *ClientPacketAddrConn) Upstream() any {
|
||||
return c.ExtendedConn
|
||||
}
|
||||
|
|
|
@ -112,6 +112,17 @@ func (c *ServerConn) WriteBuffer(buffer *buf.Buffer) error {
|
|||
return c.ExtendedConn.WriteBuffer(buffer)
|
||||
}
|
||||
|
||||
func (c *ServerConn) Headroom() int {
|
||||
if !c.responseWrite {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *ServerConn) Upstream() any {
|
||||
return c.ExtendedConn
|
||||
}
|
||||
|
||||
var (
|
||||
_ N.HandshakeConn = (*ServerPacketConn)(nil)
|
||||
_ N.PacketConn = (*ServerPacketConn)(nil)
|
||||
|
@ -160,6 +171,17 @@ func (c *ServerPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksad
|
|||
return c.ExtendedConn.WriteBuffer(buffer)
|
||||
}
|
||||
|
||||
func (c *ServerPacketConn) Upstream() any {
|
||||
return c.ExtendedConn
|
||||
}
|
||||
|
||||
func (c *ServerPacketConn) Headroom() int {
|
||||
if !c.responseWrite {
|
||||
return 3
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
var (
|
||||
_ N.HandshakeConn = (*ServerPacketAddrConn)(nil)
|
||||
_ N.PacketConn = (*ServerPacketAddrConn)(nil)
|
||||
|
@ -210,3 +232,14 @@ func (c *ServerPacketAddrConn) WritePacket(buffer *buf.Buffer, destination M.Soc
|
|||
}
|
||||
return c.ExtendedConn.WriteBuffer(buffer)
|
||||
}
|
||||
|
||||
func (c *ServerPacketAddrConn) Upstream() any {
|
||||
return c.ExtendedConn
|
||||
}
|
||||
|
||||
func (c *ServerPacketAddrConn) Headroom() int {
|
||||
if !c.responseWrite {
|
||||
return 3 + M.MaxSocksaddrLength
|
||||
}
|
||||
return 2 + M.MaxSocksaddrLength
|
||||
}
|
||||
|
|
6
go.mod
6
go.mod
|
@ -13,11 +13,11 @@ require (
|
|||
github.com/hashicorp/yamux v0.1.1
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
github.com/oschwald/maxminddb-golang v1.9.0
|
||||
github.com/sagernet/sing v0.0.0-20220730061053-a21e329a2698
|
||||
github.com/sagernet/sing v0.0.0-20220730132230-401581b13944
|
||||
github.com/sagernet/sing-dns v0.0.0-20220730061139-c8e0fb296da9
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220729155919-91d2780bfc80
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220730132258-5c45f99276b8
|
||||
github.com/sagernet/sing-tun v0.0.0-20220730061211-d5dd3b3bb14a
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220726034841-4dae776653e5
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220730132251-bb961241a5d0
|
||||
github.com/spf13/cobra v1.5.0
|
||||
github.com/stretchr/testify v1.8.0
|
||||
go.uber.org/atomic v1.9.0
|
||||
|
|
12
go.sum
12
go.sum
|
@ -147,16 +147,16 @@ github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7q
|
|||
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sagernet/sing v0.0.0-20220730061053-a21e329a2698 h1:wjoF4/FOwze8cN2/EvQyyuq1tzXjxNViPIoqQ7CNIb8=
|
||||
github.com/sagernet/sing v0.0.0-20220730061053-a21e329a2698/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
||||
github.com/sagernet/sing v0.0.0-20220730132230-401581b13944 h1:2vUsxIDLiWN/eCefED06bDkMuwZaSFEn3Yzyb0VaIME=
|
||||
github.com/sagernet/sing v0.0.0-20220730132230-401581b13944/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220730061139-c8e0fb296da9 h1:2xg2bzELWQyaD5QwS3QV90RLWqjL8d6LQmKNWOI8XWQ=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220730061139-c8e0fb296da9/go.mod h1:ZSslb2fc27A1Tk3WM5yootwWLSglsxqRZv3noam5pso=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220729155919-91d2780bfc80 h1:gpCPZyZJQVn6ZTBCJ/XaYbPi6j43TdyTty/MI5bXhbE=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220729155919-91d2780bfc80/go.mod h1:mH6wE4b5FZp1Q/meATe4tjiPjvQO9E7Lr0FBBwFYp4I=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220730132258-5c45f99276b8 h1:d6Sda+GXFRvKwRlE9fiwC32p1/vEVArZ7PgvyCg9TAI=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220730132258-5c45f99276b8/go.mod h1:aNTIkd+bCIUgr5C43aZBGXDxIc0Y9NOozLLzH2vUydM=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220730061211-d5dd3b3bb14a h1:ULsuxdirFkCUNmcDENQCjfWl/28G6rzgs2xiZFSBSZc=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220730061211-d5dd3b3bb14a/go.mod h1:1V/Scct3DGHi925AasPCj1k+6SRWIcg0TvRHM0ZXB8I=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220726034841-4dae776653e5 h1:TNguWTPF6gxX/gR02hY3LGviUn6LGlDPofE6lpSJWeo=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220726034841-4dae776653e5/go.mod h1:Q8csko2kQZHRZTz8ztqELrJB22HV60/tztPVgACV84E=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220730132251-bb961241a5d0 h1:BE+4nxv3zXp+BLmnkWyZRKo5fpoADZKRSw095FgdH3M=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220730132251-bb961241a5d0/go.mod h1:NnKMgOr0WvyHsLICWTIz4xW3+yd3Ft2BtU8N5ycT4OU=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
|
||||
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
|
||||
|
|
|
@ -10,8 +10,8 @@ require (
|
|||
github.com/docker/docker v20.10.17+incompatible
|
||||
github.com/docker/go-connections v0.4.0
|
||||
github.com/gofrs/uuid v4.2.0+incompatible
|
||||
github.com/sagernet/sing v0.0.0-20220730061053-a21e329a2698
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220729155919-91d2780bfc80
|
||||
github.com/sagernet/sing v0.0.0-20220730132230-401581b13944
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220730132258-5c45f99276b8
|
||||
github.com/spyzhov/ajson v0.7.1
|
||||
github.com/stretchr/testify v1.8.0
|
||||
golang.org/x/net v0.0.0-20220728211354-c7608f3a8462
|
||||
|
@ -54,7 +54,7 @@ require (
|
|||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/sagernet/sing-dns v0.0.0-20220730061139-c8e0fb296da9 // indirect
|
||||
github.com/sagernet/sing-tun v0.0.0-20220730061211-d5dd3b3bb14a // indirect
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220726034841-4dae776653e5 // indirect
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220730132251-bb961241a5d0 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/vishvananda/netlink v1.1.0 // indirect
|
||||
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
|
||||
|
|
12
test/go.sum
12
test/go.sum
|
@ -172,16 +172,16 @@ github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:
|
|||
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/sagernet/sing v0.0.0-20220730061053-a21e329a2698 h1:wjoF4/FOwze8cN2/EvQyyuq1tzXjxNViPIoqQ7CNIb8=
|
||||
github.com/sagernet/sing v0.0.0-20220730061053-a21e329a2698/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
||||
github.com/sagernet/sing v0.0.0-20220730132230-401581b13944 h1:2vUsxIDLiWN/eCefED06bDkMuwZaSFEn3Yzyb0VaIME=
|
||||
github.com/sagernet/sing v0.0.0-20220730132230-401581b13944/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220730061139-c8e0fb296da9 h1:2xg2bzELWQyaD5QwS3QV90RLWqjL8d6LQmKNWOI8XWQ=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220730061139-c8e0fb296da9/go.mod h1:ZSslb2fc27A1Tk3WM5yootwWLSglsxqRZv3noam5pso=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220729155919-91d2780bfc80 h1:gpCPZyZJQVn6ZTBCJ/XaYbPi6j43TdyTty/MI5bXhbE=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220729155919-91d2780bfc80/go.mod h1:mH6wE4b5FZp1Q/meATe4tjiPjvQO9E7Lr0FBBwFYp4I=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220730132258-5c45f99276b8 h1:d6Sda+GXFRvKwRlE9fiwC32p1/vEVArZ7PgvyCg9TAI=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220730132258-5c45f99276b8/go.mod h1:aNTIkd+bCIUgr5C43aZBGXDxIc0Y9NOozLLzH2vUydM=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220730061211-d5dd3b3bb14a h1:ULsuxdirFkCUNmcDENQCjfWl/28G6rzgs2xiZFSBSZc=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220730061211-d5dd3b3bb14a/go.mod h1:1V/Scct3DGHi925AasPCj1k+6SRWIcg0TvRHM0ZXB8I=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220726034841-4dae776653e5 h1:TNguWTPF6gxX/gR02hY3LGviUn6LGlDPofE6lpSJWeo=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220726034841-4dae776653e5/go.mod h1:Q8csko2kQZHRZTz8ztqELrJB22HV60/tztPVgACV84E=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220730132251-bb961241a5d0 h1:BE+4nxv3zXp+BLmnkWyZRKo5fpoADZKRSw095FgdH3M=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220730132251-bb961241a5d0/go.mod h1:NnKMgOr0WvyHsLICWTIz4xW3+yd3Ft2BtU8N5ycT4OU=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
|
||||
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
|
||||
|
|
Loading…
Reference in a new issue