diff --git a/.github/update_dependencies.sh b/.github/update_dependencies.sh index 2ec62da..d63123b 100755 --- a/.github/update_dependencies.sh +++ b/.github/update_dependencies.sh @@ -2,5 +2,5 @@ PROJECTS=$(dirname "$0")/../.. -go get -v github.com/sagernet/sing@$(git -C $PROJECTS/sing rev-parse HEAD) +go get -x github.com/sagernet/sing@$(git -C $PROJECTS/sing rev-parse HEAD) go mod tidy diff --git a/go.mod b/go.mod index 7f759f3..a7ef22c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/sagernet/sing-shadowsocks go 1.18 require ( - github.com/sagernet/sing v0.0.0-20220530023925-d634f5f8d1f9 + github.com/sagernet/sing v0.0.0-20220530041323-c82c144a8e00 golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e lukechampine.com/blake3 v1.1.7 ) diff --git a/go.sum b/go.sum index c38cf22..f3ed1db 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ 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/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= -github.com/sagernet/sing v0.0.0-20220530023925-d634f5f8d1f9 h1:KqmiPU4dmM5bXsWF3i321bhdaY0iw9aSk9lHnKFqcA8= -github.com/sagernet/sing v0.0.0-20220530023925-d634f5f8d1f9/go.mod h1:w2HnJzXKHpD6F5Z/9XlSD4qbcpHY2RSZuQnFzqgELMg= +github.com/sagernet/sing v0.0.0-20220530041323-c82c144a8e00 h1:kQCITv1yBrSSL6RIBPWTe1+goyWLbS4DELWTeRKmoh8= +github.com/sagernet/sing v0.0.0-20220530041323-c82c144a8e00/go.mod h1:w2HnJzXKHpD6F5Z/9XlSD4qbcpHY2RSZuQnFzqgELMg= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= diff --git a/none.go b/none.go index 6177e7f..9c25317 100644 --- a/none.go +++ b/none.go @@ -187,6 +187,9 @@ func (s *NoneService) NewConnection(ctx context.Context, conn net.Conn, metadata return s.handler.NewConnection(ctx, conn, metadata) } +func (s *NoneService) WriteIsThreadUnsafe() { +} + func (s *NoneService) NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { destination, err := M.SocksaddrSerializer.ReadAddrPort(buffer) if err != nil { diff --git a/shadowaead/service.go b/shadowaead/service.go index b3e1ccf..6d5a1c5 100644 --- a/shadowaead/service.go +++ b/shadowaead/service.go @@ -189,6 +189,9 @@ func (c *serverConn) Upstream() any { return c.Conn } +func (s *Service) WriteIsThreadUnsafe() { +} + func (s *Service) NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(ctx, conn, buffer, metadata) if err != nil { diff --git a/shadowaead_2022/relay.go b/shadowaead_2022/relay.go index c1c5ec4..cb65018 100644 --- a/shadowaead_2022/relay.go +++ b/shadowaead_2022/relay.go @@ -175,6 +175,9 @@ func (s *Relay[U]) newConnection(ctx context.Context, conn net.Conn, metadata M. return s.handler.NewConnection(ctx, conn, metadata) } +func (s *Relay[U]) WriteIsThreadUnsafe() { +} + func (s *Relay[U]) NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(ctx, conn, buffer, metadata) if err != nil { diff --git a/shadowaead_2022/service.go b/shadowaead_2022/service.go index d255bc5..1823541 100644 --- a/shadowaead_2022/service.go +++ b/shadowaead_2022/service.go @@ -306,6 +306,9 @@ func (c *serverConn) Upstream() any { return c.Conn } +func (s *Service) WriteIsThreadUnsafe() { +} + func (s *Service) NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(ctx, conn, buffer, metadata) if err != nil { @@ -489,21 +492,21 @@ func (s *serverUDPSession) nextPacketId() uint64 { return atomic.AddUint64(&s.packetId, 1) } -func (m *Service) newUDPSession() *serverUDPSession { +func (s *Service) newUDPSession() *serverUDPSession { session := &serverUDPSession{} - if m.udpCipher != nil { + if s.udpCipher != nil { session.rng = Blake3KeyedHash(rand.Reader) common.Must(binary.Read(session.rng, binary.BigEndian, &session.sessionId)) } else { common.Must(binary.Read(rand.Reader, binary.BigEndian, &session.sessionId)) } session.packetId-- - if m.udpCipher == nil { + if s.udpCipher == nil { sessionId := make([]byte, 8) binary.BigEndian.PutUint64(sessionId, session.sessionId) - key := SessionKey(m.psk, sessionId, m.keySaltLength) + key := SessionKey(s.psk, sessionId, s.keySaltLength) var err error - session.cipher, err = m.constructor(common.Dup(key)) + session.cipher, err = s.constructor(common.Dup(key)) common.Must(err) common.KeepAlive(key) } diff --git a/shadowaead_2022/service_multi.go b/shadowaead_2022/service_multi.go index a4dec1f..54f6e38 100644 --- a/shadowaead_2022/service_multi.go +++ b/shadowaead_2022/service_multi.go @@ -235,6 +235,9 @@ func (s *MultiService[U]) newConnection(ctx context.Context, conn net.Conn, meta }, metadata) } +func (s *MultiService[U]) WriteIsThreadUnsafe() { +} + func (s *MultiService[U]) NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error { err := s.newPacket(ctx, conn, buffer, metadata) if err != nil {