mirror of
https://github.com/SagerNet/sing-shadowtls.git
synced 2025-04-01 19:27:36 +03:00
Add read deadline implementation
This commit is contained in:
parent
78d8070aa6
commit
9abef01943
4 changed files with 16 additions and 14 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/sagernet/sing/common/bufio/deadline"
|
||||
"github.com/sagernet/sing/common/debug"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
|
@ -66,7 +67,7 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
shadowTLSConn, err := c.DialContextConn(ctx, conn)
|
||||
shadowTLSConn, err := c.DialContextConn(ctx, conn)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, err
|
||||
|
@ -95,7 +96,7 @@ func (c *Client) DialContextConn(ctx context.Context, conn net.Conn) (net.Conn,
|
|||
return nil, err
|
||||
}
|
||||
c.logger.TraceContext(ctx, "clint handshake finished")
|
||||
return newClientConn(hashConn), nil
|
||||
return deadline.NewConn(newClientConn(hashConn)), nil
|
||||
case 3:
|
||||
stream := newStreamWrapper(conn, c.password)
|
||||
err := c.tlsHandshake(ctx, stream, generateSessionID(c.password))
|
||||
|
@ -116,6 +117,6 @@ func (c *Client) DialContextConn(ctx context.Context, conn net.Conn) (net.Conn,
|
|||
hmacVerify := hmac.New(sha1.New, []byte(c.password))
|
||||
hmacVerify.Write(serverRandom)
|
||||
hmacVerify.Write([]byte("S"))
|
||||
return newVerifiedConn(conn, hmacAdd, hmacVerify, readHMAC), nil
|
||||
return deadline.NewConn(newVerifiedConn(conn, hmacAdd, hmacVerify, readHMAC)), nil
|
||||
}
|
||||
}
|
||||
|
|
6
go.mod
6
go.mod
|
@ -3,7 +3,7 @@ module github.com/sagernet/sing-shadowtls
|
|||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/sagernet/sing v0.1.6
|
||||
golang.org/x/crypto v0.6.0
|
||||
golang.org/x/sys v0.5.0
|
||||
github.com/sagernet/sing v0.2.3-0.20230409094616-7f8eaee1b6c8
|
||||
golang.org/x/crypto v0.8.0
|
||||
golang.org/x/sys v0.7.0
|
||||
)
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,6 +1,6 @@
|
|||
github.com/sagernet/sing v0.1.6 h1:Qy63OUfKpcqKjfd5rPmUlj0RGjHZSK/PJn0duyCCsRg=
|
||||
github.com/sagernet/sing v0.1.6/go.mod h1:JLSXsPTGRJFo/3X7EcAOCUgJH2/gAoxSJgBsnCZRp/w=
|
||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/sagernet/sing v0.2.3-0.20230409094616-7f8eaee1b6c8 h1:BWQjek8tNzDzCeHh/8yvjfZ8Id0tl+6pJ+gcPI8tjl8=
|
||||
github.com/sagernet/sing v0.2.3-0.20230409094616-7f8eaee1b6c8/go.mod h1:Ta8nHnDLAwqySzKhGoKk4ZIB+vJ3GTKj7UPrWYvM+4w=
|
||||
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
|
||||
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
|
||||
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/sagernet/sing/common/auth"
|
||||
"github.com/sagernet/sing/common/buf"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
"github.com/sagernet/sing/common/bufio/deadline"
|
||||
"github.com/sagernet/sing/common/debug"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/logger"
|
||||
|
@ -144,7 +145,7 @@ func (s *Service) NewConnection(ctx context.Context, conn net.Conn, metadata M.M
|
|||
if err == nil {
|
||||
s.logger.TraceContext(ctx, "handshake finished")
|
||||
handshakeConn.Close()
|
||||
return s.handler.NewConnection(ctx, bufio.NewCachedConn(newConn(conn), request), metadata)
|
||||
return s.handler.NewConnection(ctx, bufio.NewCachedConn(deadline.NewConn(newConn(conn)), request), metadata)
|
||||
} else if err == os.ErrPermission {
|
||||
s.logger.WarnContext(ctx, "fallback connection")
|
||||
hashConn.Fallback()
|
||||
|
@ -247,6 +248,6 @@ func (s *Service) NewConnection(ctx context.Context, conn net.Conn, metadata M.M
|
|||
return E.Cause(err, "handshake relay")
|
||||
}
|
||||
s.logger.TraceContext(ctx, "handshake relay finished")
|
||||
return s.handler.NewConnection(ctx, bufio.NewCachedConn(newVerifiedConn(conn, hmacAdd, hmacVerify, nil), clientFirstFrame), metadata)
|
||||
return s.handler.NewConnection(ctx, bufio.NewCachedConn(deadline.NewConn(newVerifiedConn(conn, hmacAdd, hmacVerify, nil)), clientFirstFrame), metadata)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue