Update BBR and Hysteria congestion control & Migrate legacy Hysteria protocol to library

This commit is contained in:
世界
2023-10-21 12:00:00 +08:00
parent 3b161ab30c
commit 31c294d998
17 changed files with 214 additions and 1402 deletions

View File

@@ -12,7 +12,6 @@ import (
"github.com/sagernet/sing-box/common/tls"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/transport/hysteria"
"github.com/sagernet/sing-quic"
"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/bufio"
@@ -93,7 +92,7 @@ func (c *Client) DialContext(ctx context.Context) (net.Conn, error) {
if err != nil {
return nil, err
}
return &hysteria.StreamWrapper{Conn: conn, Stream: stream}, nil
return &StreamWrapper{Conn: conn, Stream: stream}, nil
}
func (c *Client) Close() error {

View File

@@ -12,7 +12,6 @@ import (
"github.com/sagernet/sing-box/common/tls"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing-box/transport/hysteria"
"github.com/sagernet/sing-quic"
"github.com/sagernet/sing/common"
M "github.com/sagernet/sing/common/metadata"
@@ -86,7 +85,7 @@ func (s *Server) streamAcceptLoop(conn quic.Connection) error {
if err != nil {
return err
}
go s.handler.NewConnection(conn.Context(), &hysteria.StreamWrapper{Conn: conn, Stream: stream}, M.Metadata{})
go s.handler.NewConnection(conn.Context(), &StreamWrapper{Conn: conn, Stream: stream}, M.Metadata{})
}
}

View File

@@ -0,0 +1,41 @@
package v2rayquic
import (
"net"
"github.com/sagernet/quic-go"
"github.com/sagernet/sing/common/baderror"
)
type StreamWrapper struct {
Conn quic.Connection
quic.Stream
}
func (s *StreamWrapper) Read(p []byte) (n int, err error) {
n, err = s.Stream.Read(p)
return n, baderror.WrapQUIC(err)
}
func (s *StreamWrapper) Write(p []byte) (n int, err error) {
n, err = s.Stream.Write(p)
return n, baderror.WrapQUIC(err)
}
func (s *StreamWrapper) LocalAddr() net.Addr {
return s.Conn.LocalAddr()
}
func (s *StreamWrapper) RemoteAddr() net.Addr {
return s.Conn.RemoteAddr()
}
func (s *StreamWrapper) Upstream() any {
return s.Stream
}
func (s *StreamWrapper) Close() error {
s.CancelRead(0)
s.Stream.Close()
return nil
}