Add service.NewConnection0 stub func

This commit is contained in:
世界 2023-09-28 15:24:29 +08:00
parent 0c1612d823
commit f86df97602
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 20 additions and 6 deletions

View file

@ -31,8 +31,9 @@ import (
)
var (
ErrNoPadding = E.New("bad request: missing payload or padding")
ErrBadPadding = E.New("bad request: damaged padding")
ErrInvalidRequest = E.New("invalid request")
ErrNoPadding = E.New("bad request: missing payload or padding")
ErrBadPadding = E.New("bad request: damaged padding")
)
var _ shadowsocks.Service = (*Service)(nil)

View file

@ -7,6 +7,7 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/binary"
"io"
"math"
"net"
"os"
@ -115,16 +116,24 @@ func (s *MultiService[U]) UpdateUsersWithPasswords(userList []U, passwordList []
}
func (s *MultiService[U]) NewConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
err := s.newConnection(ctx, conn, metadata)
err := s.NewConnection0(ctx, conn, metadata, conn, nil)
if err != nil {
err = &shadowsocks.ServerConnError{Conn: conn, Source: metadata.Source, Cause: err}
}
return err
}
func (s *MultiService[U]) newConnection(ctx context.Context, conn net.Conn, metadata M.Metadata) error {
func (s *MultiService[U]) NewConnection0(ctx context.Context, conn net.Conn, metadata M.Metadata, handshakeReader io.Reader, handshakeSuccess func()) error {
requestHeader := make([]byte, s.keySaltLength+aes.BlockSize+shadowaead.Overhead+RequestHeaderFixedChunkLength)
n, err := conn.Read(requestHeader)
var (
n int
err error
)
if handshakeSuccess != nil {
n, err = io.ReadFull(handshakeReader, requestHeader)
} else {
n, err = handshakeReader.Read(requestHeader)
}
if err != nil {
return err
} else if n < len(requestHeader) {
@ -158,7 +167,11 @@ func (s *MultiService[U]) newConnection(ctx context.Context, conn net.Conn, meta
user = u
uPSK = s.uPSK[u]
} else {
return E.New("invalid request")
return ErrInvalidRequest
}
if handshakeSuccess != nil {
handshakeSuccess()
}
requestKey := SessionKey(uPSK, requestSalt, s.keySaltLength)