Skip to content

Commit

Permalink
Implement read waiter for ss2022 UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 6, 2023
1 parent e07da80 commit 6ed02b4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module github.com/sagernet/sing-shadowsocks2
go 1.18

require (
github.com/sagernet/sing v0.2.17
github.com/sagernet/sing v0.2.19-0.20231206123939-86c131fc0547
golang.org/x/crypto v0.15.0
lukechampine.com/blake3 v1.2.1
)

require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
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.20231206123939-86c131fc0547 h1:Mco2TffcdPMlmzbcGmbKd6Vm6dEBJH2VgjO6H1XfZzY=
github.com/sagernet/sing v0.2.19-0.20231206123939-86c131fc0547/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=
8 changes: 8 additions & 0 deletions shadowaead/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ func (c *clientPacketConn) RearHeadroom() int {
return shadowio.Overhead
}

func (c *clientPacketConn) ReaderMTU() int {
return MaxPacketSize
}

func (c *clientPacketConn) WriterMTU() int {
return MaxPacketSize
}

func (c *clientPacketConn) Upstream() any {
return c.AbstractConn
}
42 changes: 42 additions & 0 deletions shadowaead_2022/method_wait.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package shadowaead_2022

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 = (*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(newBuffer func() *buf.Buffer) {
w.readWaiter.InitializeReadWaiter(newBuffer)
}

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
}

0 comments on commit 6ed02b4

Please sign in to comment.