mirror of
https://github.com/SagerNet/sing-shadowsocks.git
synced 2025-04-05 04:47:41 +03:00
Update headroom usage
This commit is contained in:
parent
a91eacdd01
commit
7e47fd1a99
8 changed files with 45 additions and 13 deletions
4
go.mod
4
go.mod
|
@ -3,12 +3,12 @@ module github.com/sagernet/sing-shadowsocks
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/sagernet/sing v0.0.0-20220801112236-1bb95f9661fc
|
github.com/sagernet/sing v0.0.0-20220811135544-169983a8d773
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||||
lukechampine.com/blake3 v1.1.7
|
lukechampine.com/blake3 v1.1.7
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
|
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
|
||||||
)
|
)
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -1,11 +1,11 @@
|
||||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
|
github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE=
|
||||||
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
|
github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
|
||||||
github.com/sagernet/sing v0.0.0-20220801112236-1bb95f9661fc h1:x7H64IiqyrpxPWl/KrWkknzEK4GmpqgfZeVKFVw6E/M=
|
github.com/sagernet/sing v0.0.0-20220811135544-169983a8d773 h1:n88c8oBC6GWbEW2+F4HkVAji+puSW3GYGrbnXmuVYsw=
|
||||||
github.com/sagernet/sing v0.0.0-20220801112236-1bb95f9661fc/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
github.com/sagernet/sing v0.0.0-20220811135544-169983a8d773/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
|
lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0=
|
||||||
lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
|
lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA=
|
||||||
|
|
4
none.go
4
none.go
|
@ -89,7 +89,7 @@ func (c *noneConn) WriteBuffer(buffer *buf.Buffer) error {
|
||||||
return common.Error(c.Conn.Write(buffer.Bytes()))
|
return common.Error(c.Conn.Write(buffer.Bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *noneConn) Headroom() int {
|
func (c *noneConn) FrontHeadroom() int {
|
||||||
if !c.handshake {
|
if !c.handshake {
|
||||||
return M.SocksaddrSerializer.AddrPortLen(c.destination)
|
return M.SocksaddrSerializer.AddrPortLen(c.destination)
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ func (w *nonePacketWriter) Upstream() any {
|
||||||
return w.source
|
return w.source
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *nonePacketWriter) Headroom() int {
|
func (w *nonePacketWriter) FrontHeadroom() int {
|
||||||
return M.MaxSocksaddrLength
|
return M.MaxSocksaddrLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -310,10 +310,22 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientPacketConn) Headroom() int {
|
func (c *clientPacketConn) FrontHeadroom() int {
|
||||||
return c.keySaltLength + M.MaxSocksaddrLength
|
return c.keySaltLength + M.MaxSocksaddrLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *clientPacketConn) RearHeadroom() int {
|
||||||
|
return Overhead
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *clientPacketConn) ReaderMTU() int {
|
||||||
|
return MaxPacketSize
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *clientPacketConn) WriterMTU() int {
|
||||||
|
return MaxPacketSize
|
||||||
|
}
|
||||||
|
|
||||||
func (c *clientPacketConn) Upstream() any {
|
func (c *clientPacketConn) Upstream() any {
|
||||||
return c.Conn
|
return c.Conn
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,6 +208,10 @@ func (c *serverConn) Upstream() any {
|
||||||
return c.Conn
|
return c.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) ReaderMTU() int {
|
||||||
|
return MaxPacketSize
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) WriteIsThreadUnsafe() {
|
func (s *Service) WriteIsThreadUnsafe() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,10 +284,18 @@ func (w *serverPacketWriter) WritePacket(buffer *buf.Buffer, destination M.Socks
|
||||||
return w.source.WritePacket(buffer, M.SocksaddrFromNet(w.nat.LocalAddr()))
|
return w.source.WritePacket(buffer, M.SocksaddrFromNet(w.nat.LocalAddr()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *serverPacketWriter) Headroom() int {
|
func (w *serverPacketWriter) FrontHeadroom() int {
|
||||||
return w.keySaltLength + M.MaxSocksaddrLength
|
return w.keySaltLength + M.MaxSocksaddrLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *serverPacketWriter) RearHeadroom() int {
|
||||||
|
return Overhead
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *serverPacketWriter) WriterMTU() int {
|
||||||
|
return MaxPacketSize
|
||||||
|
}
|
||||||
|
|
||||||
func (w *serverPacketWriter) Upstream() any {
|
func (w *serverPacketWriter) Upstream() any {
|
||||||
return w.source
|
return w.source
|
||||||
}
|
}
|
||||||
|
|
|
@ -802,7 +802,7 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientPacketConn) Headroom() int {
|
func (c *clientPacketConn) FrontHeadroom() int {
|
||||||
var overHead int
|
var overHead int
|
||||||
if c.udpCipher != nil {
|
if c.udpCipher != nil {
|
||||||
overHead = PacketNonceSize + shadowaead.Overhead
|
overHead = PacketNonceSize + shadowaead.Overhead
|
||||||
|
@ -822,6 +822,10 @@ func (c *clientPacketConn) Headroom() int {
|
||||||
return overHead
|
return overHead
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *clientPacketConn) RearHeadroom() int {
|
||||||
|
return shadowaead.Overhead
|
||||||
|
}
|
||||||
|
|
||||||
type udpSession struct {
|
type udpSession struct {
|
||||||
sessionId uint64
|
sessionId uint64
|
||||||
packetId uint64
|
packetId uint64
|
||||||
|
|
|
@ -550,7 +550,7 @@ func (w *serverPacketWriter) WritePacket(buffer *buf.Buffer, destination M.Socks
|
||||||
return w.source.WritePacket(buffer, M.SocksaddrFromNet(w.nat.LocalAddr()))
|
return w.source.WritePacket(buffer, M.SocksaddrFromNet(w.nat.LocalAddr()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *serverPacketWriter) Headroom() int {
|
func (w *serverPacketWriter) FrontHeadroom() int {
|
||||||
var hdrLen int
|
var hdrLen int
|
||||||
if w.udpCipher != nil {
|
if w.udpCipher != nil {
|
||||||
hdrLen = PacketNonceSize
|
hdrLen = PacketNonceSize
|
||||||
|
@ -565,6 +565,10 @@ func (w *serverPacketWriter) Headroom() int {
|
||||||
return hdrLen
|
return hdrLen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *serverPacketWriter) RearHeadroom() int {
|
||||||
|
return shadowaead.Overhead
|
||||||
|
}
|
||||||
|
|
||||||
func (w *serverPacketWriter) Upstream() any {
|
func (w *serverPacketWriter) Upstream() any {
|
||||||
return w.source
|
return w.source
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *clientPacketConn) Headroom() int {
|
func (c *clientPacketConn) FrontHeadroom() int {
|
||||||
return c.saltLength + M.MaxSocksaddrLength
|
return c.saltLength + M.MaxSocksaddrLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue