mirror of
https://github.com/SagerNet/sing-quic.git
synced 2025-04-04 04:17:38 +03:00
Update handler usages
This commit is contained in:
parent
2419e1d7f7
commit
20f4b153bc
7 changed files with 19 additions and 48 deletions
|
@ -46,8 +46,8 @@ type ServiceOptions struct {
|
|||
}
|
||||
|
||||
type ServerHandler interface {
|
||||
N.TCPConnectionHandler
|
||||
N.UDPConnectionHandler
|
||||
N.TCPConnectionHandlerEx
|
||||
N.UDPConnectionHandlerEx
|
||||
}
|
||||
|
||||
type Service[U comparable] struct {
|
||||
|
@ -244,10 +244,7 @@ func (s *serverSession[U]) handleStream(stream quic.Stream) error {
|
|||
}
|
||||
ctx := auth.ContextWithUser(s.ctx, s.authUser)
|
||||
if !request.UDP {
|
||||
_ = s.handler.NewConnection(ctx, &serverConn{Stream: stream}, M.Metadata{
|
||||
Source: s.source,
|
||||
Destination: M.ParseSocksaddrHostPort(request.Host, request.Port),
|
||||
})
|
||||
s.handler.NewConnectionEx(ctx, &serverConn{Stream: stream}, s.source, M.ParseSocksaddrHostPort(request.Host, request.Port), nil)
|
||||
} else {
|
||||
if s.udpDisabled {
|
||||
return WriteServerResponse(stream, ServerResponse{
|
||||
|
@ -278,10 +275,7 @@ func (s *serverSession[U]) handleStream(stream quic.Stream) error {
|
|||
return err
|
||||
}
|
||||
newCtx, newConn := canceler.NewPacketConn(udpConn.ctx, udpConn, s.udpTimeout)
|
||||
go s.handler.NewPacketConnection(newCtx, newConn, M.Metadata{
|
||||
Source: s.source,
|
||||
Destination: M.ParseSocksaddrHostPort(request.Host, request.Port),
|
||||
})
|
||||
go s.handler.NewPacketConnectionEx(newCtx, newConn, s.source, M.ParseSocksaddrHostPort(request.Host, request.Port), nil)
|
||||
holdBuffer := make([]byte, 1024)
|
||||
for {
|
||||
_, hErr := stream.Read(holdBuffer)
|
||||
|
@ -330,7 +324,7 @@ type serverConn struct {
|
|||
|
||||
func (c *serverConn) HandshakeFailure(err error) error {
|
||||
if c.responseWritten {
|
||||
return os.ErrClosed
|
||||
return os.ErrInvalid
|
||||
}
|
||||
c.responseWritten = true
|
||||
return WriteServerResponse(c.Stream, ServerResponse{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue