-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement read waiter for none/aead/aead-2022
- Loading branch information
1 parent
e07da80
commit 1d569c2
Showing
9 changed files
with
265 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cipher | ||
|
||
import ( | ||
"github.com/sagernet/sing/common/buf" | ||
"github.com/sagernet/sing/common/bufio" | ||
M "github.com/sagernet/sing/common/metadata" | ||
N "github.com/sagernet/sing/common/network" | ||
) | ||
|
||
var _ N.PacketReadWaitCreator = (*nonePacketConn)(nil) | ||
|
||
func (c *nonePacketConn) CreateReadWaiter() (N.PacketReadWaiter, bool) { | ||
readWaiter, isReadWaiter := bufio.CreateReadWaiter(c.conn) | ||
if !isReadWaiter { | ||
return nil, false | ||
} | ||
return &nonePacketReadWaiter{readWaiter}, true | ||
} | ||
|
||
var _ N.PacketReadWaiter = (*nonePacketReadWaiter)(nil) | ||
|
||
type nonePacketReadWaiter struct { | ||
readWaiter N.ReadWaiter | ||
} | ||
|
||
func (w *nonePacketReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) { | ||
return w.readWaiter.InitializeReadWaiter(options) | ||
} | ||
|
||
func (w *nonePacketReadWaiter) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) { | ||
buffer, err = w.readWaiter.WaitReadBuffer() | ||
if err != nil { | ||
return | ||
} | ||
destination, err = M.SocksaddrSerializer.ReadAddrPort(buffer) | ||
if err != nil { | ||
buffer.Release() | ||
return nil, M.Socksaddr{}, err | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= | ||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= | ||
github.com/sagernet/sing v0.2.17 h1:vMPKb3MV0Aa5ws4dCJkRI8XEjrsUcDn810czd0FwmzI= | ||
github.com/sagernet/sing v0.2.17/go.mod h1:OL6k2F0vHmEzXz2KW19qQzu172FDgSbUSODylighuVo= | ||
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= | ||
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= | ||
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= | ||
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/sagernet/sing v0.3.0-rc.2 h1:l5rq+bTrNhpAPd2Vjzi/sEhil4O6Bb1CKv6LdPLJKug= | ||
github.com/sagernet/sing v0.3.0-rc.2/go.mod h1:9pfuAH6mZfgnz/YjP6xu5sxx882rfyjpcrTdUpd6w3g= | ||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= | ||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= | ||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= | ||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= | ||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI= | ||
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package shadowaead | ||
|
||
import ( | ||
"github.com/sagernet/sing/common/buf" | ||
"github.com/sagernet/sing/common/bufio" | ||
M "github.com/sagernet/sing/common/metadata" | ||
N "github.com/sagernet/sing/common/network" | ||
) | ||
|
||
var _ N.ReadWaiter = (*clientConn)(nil) | ||
|
||
func (c *clientConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) { | ||
if c.reader == nil { | ||
c.readWaitOptions = options | ||
return options.NeedHeadroom() | ||
} | ||
return c.reader.InitializeReadWaiter(options) | ||
} | ||
|
||
func (c *clientConn) WaitReadBuffer() (buffer *buf.Buffer, err error) { | ||
if c.reader == nil { | ||
err = c.readResponse() | ||
if err != nil { | ||
return | ||
} | ||
} | ||
return c.reader.WaitReadBuffer() | ||
} | ||
|
||
var _ N.PacketReadWaitCreator = (*clientPacketConn)(nil) | ||
|
||
func (c *clientPacketConn) CreateReadWaiter() (N.PacketReadWaiter, bool) { | ||
readWaiter, isReadWaiter := bufio.CreateReadWaiter(c.reader) | ||
if !isReadWaiter { | ||
return nil, false | ||
} | ||
return &clientPacketReadWaiter{c, readWaiter}, true | ||
} | ||
|
||
var _ N.PacketReadWaiter = (*clientPacketReadWaiter)(nil) | ||
|
||
type clientPacketReadWaiter struct { | ||
*clientPacketConn | ||
readWaiter N.ReadWaiter | ||
} | ||
|
||
func (w *clientPacketReadWaiter) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) { | ||
return w.readWaiter.InitializeReadWaiter(options) | ||
} | ||
|
||
func (w *clientPacketReadWaiter) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) { | ||
buffer, err = w.readWaiter.WaitReadBuffer() | ||
if err != nil { | ||
return | ||
} | ||
destination, err = w.readPacket(buffer) | ||
if err != nil { | ||
buffer.Release() | ||
return nil, M.Socksaddr{}, err | ||
} | ||
return | ||
} |
Oops, something went wrong.