Update handler usages

This commit is contained in:
世界 2024-11-15 16:34:19 +08:00
parent 2419e1d7f7
commit 20f4b153bc
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
7 changed files with 19 additions and 48 deletions

View file

@ -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{