mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 20:07:38 +03:00
Fix ss-server udp
This commit is contained in:
parent
6973a8f4c3
commit
58e06dc57c
5 changed files with 10 additions and 19 deletions
|
@ -41,7 +41,6 @@ func (e *ServerConnError) Error() string {
|
|||
}
|
||||
|
||||
type ServerPacketError struct {
|
||||
N.PacketConn
|
||||
Source M.Socksaddr
|
||||
Cause error
|
||||
}
|
||||
|
|
|
@ -201,7 +201,7 @@ func (c *serverConn) WriterReplaceable() bool {
|
|||
func (s *Service) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error {
|
||||
err := s.newPacket(conn, buffer, metadata)
|
||||
if err != nil {
|
||||
err = &shadowsocks.ServerPacketError{PacketConn: conn, Source: metadata.Source, Cause: err}
|
||||
err = &shadowsocks.ServerPacketError{Source: metadata.Source, Cause: err}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -67,7 +67,6 @@ var List = []string{
|
|||
func New(method string, pskList [][]byte, password string, secureRNG io.Reader) (shadowsocks.Method, error) {
|
||||
m := &Method{
|
||||
name: method,
|
||||
pskList: pskList,
|
||||
secureRNG: secureRNG,
|
||||
replayFilter: replay.NewCuckoo(60),
|
||||
}
|
||||
|
@ -125,6 +124,7 @@ func New(method string, pskList [][]byte, password string, secureRNG io.Reader)
|
|||
m.udpCipher = newXChacha20Poly1305(pskList[0])
|
||||
}
|
||||
|
||||
m.pskList = pskList
|
||||
return m, nil
|
||||
}
|
||||
|
||||
|
@ -479,9 +479,6 @@ func (c *clientPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksad
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.udpCipher != nil {
|
||||
c.udpCipher.Seal(buffer.Index(dataIndex), buffer.To(dataIndex), buffer.From(dataIndex), nil)
|
||||
buffer.Extend(c.udpCipher.Overhead())
|
||||
|
@ -687,9 +684,6 @@ func (c *clientPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if c.udpCipher != nil {
|
||||
c.udpCipher.Seal(buffer.Index(dataIndex), buffer.To(dataIndex), buffer.From(dataIndex), nil)
|
||||
buffer.Extend(c.udpCipher.Overhead())
|
||||
|
|
|
@ -71,17 +71,14 @@ func NewService(method string, psk []byte, password string, secureRNG io.Reader,
|
|||
s.constructor = newChacha20Poly1305
|
||||
}
|
||||
|
||||
if len(psk) == s.keySaltLength {
|
||||
s.psk = psk
|
||||
} else if len(psk) != 0 {
|
||||
if len(psk) < s.keySaltLength {
|
||||
return nil, shadowsocks.ErrBadKey
|
||||
}
|
||||
s.psk = Key(psk, s.keySaltLength)
|
||||
if len(psk) < s.keySaltLength {
|
||||
return nil, shadowsocks.ErrBadKey
|
||||
} else if len(psk) > s.keySaltLength {
|
||||
psk = Key(psk, s.keySaltLength)
|
||||
} else if password == "" {
|
||||
return nil, ErrMissingPasswordPSK
|
||||
} else {
|
||||
s.psk = Key([]byte(password), s.keySaltLength)
|
||||
psk = Key([]byte(password), s.keySaltLength)
|
||||
}
|
||||
|
||||
switch method {
|
||||
|
@ -93,6 +90,7 @@ func NewService(method string, psk []byte, password string, secureRNG io.Reader,
|
|||
s.udpCipher = newXChacha20Poly1305(psk)
|
||||
}
|
||||
|
||||
s.psk = psk
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
@ -271,7 +269,7 @@ func (c *serverConn) WriterReplaceable() bool {
|
|||
func (s *Service) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error {
|
||||
err := s.newPacket(conn, buffer, metadata)
|
||||
if err != nil {
|
||||
err = &shadowsocks.ServerPacketError{PacketConn: conn, Source: metadata.Source, Cause: err}
|
||||
err = &shadowsocks.ServerPacketError{Source: metadata.Source, Cause: err}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ func (s *MultiService[U]) newConnection(ctx context.Context, conn net.Conn, meta
|
|||
func (s *MultiService[U]) NewPacket(conn N.PacketConn, buffer *buf.Buffer, metadata M.Metadata) error {
|
||||
err := s.newPacket(conn, buffer, metadata)
|
||||
if err != nil {
|
||||
err = &shadowsocks.ServerPacketError{PacketConn: conn, Source: metadata.Source, Cause: err}
|
||||
err = &shadowsocks.ServerPacketError{Source: metadata.Source, Cause: err}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue