-
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 5043973
Showing
9 changed files
with
258 additions
and
56 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,10 @@ | ||
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= | ||
github.com/sagernet/sing v0.2.19-0.20231207034108-445cd4f41e3f h1:hYkBnmJjVphGc4b02b4jN46ojh05vACYZI3ciD/V3pA= | ||
github.com/sagernet/sing v0.2.19-0.20231207034108-445cd4f41e3f/go.mod h1:Ce5LNojQOgOiWhiD8pPD6E9H7e2KgtOe3Zxx4Ou5u80= | ||
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= | ||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= | ||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
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 | ||
} |
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
Oops, something went wrong.