mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-17 09:49:52 +00:00
chore: remove congestion factory
This commit is contained in:
parent
7126425499
commit
ca3de154ba
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/yosuke-furukawa/json5/encoding/json5"
|
"github.com/yosuke-furukawa/json5/encoding/json5"
|
||||||
|
|
||||||
"github.com/HyNetwork/hysteria/pkg/acl"
|
"github.com/HyNetwork/hysteria/pkg/acl"
|
||||||
hyCongestion "github.com/HyNetwork/hysteria/pkg/congestion"
|
|
||||||
"github.com/HyNetwork/hysteria/pkg/core"
|
"github.com/HyNetwork/hysteria/pkg/core"
|
||||||
hyHTTP "github.com/HyNetwork/hysteria/pkg/http"
|
hyHTTP "github.com/HyNetwork/hysteria/pkg/http"
|
||||||
"github.com/HyNetwork/hysteria/pkg/obfs"
|
"github.com/HyNetwork/hysteria/pkg/obfs"
|
||||||
@ -26,7 +25,6 @@ import (
|
|||||||
"github.com/HyNetwork/hysteria/pkg/tproxy"
|
"github.com/HyNetwork/hysteria/pkg/tproxy"
|
||||||
"github.com/HyNetwork/hysteria/pkg/transport"
|
"github.com/HyNetwork/hysteria/pkg/transport"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
"github.com/lucas-clemente/quic-go/congestion"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -145,10 +143,8 @@ func client(config *clientConfig) {
|
|||||||
for {
|
for {
|
||||||
try += 1
|
try += 1
|
||||||
c, err := core.NewClient(config.Server, config.Protocol, auth, tlsConfig, quicConfig,
|
c, err := core.NewClient(config.Server, config.Protocol, auth, tlsConfig, quicConfig,
|
||||||
transport.DefaultClientTransport, up, down,
|
transport.DefaultClientTransport, up, down, obfuscator,
|
||||||
func(refBPS uint64) congestion.CongestionControl {
|
func(err error) {
|
||||||
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
|
||||||
}, obfuscator, func(err error) {
|
|
||||||
if config.QuitOnDisconnect {
|
if config.QuitOnDisconnect {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
"addr": config.Server,
|
"addr": config.Server,
|
||||||
|
@ -10,14 +10,12 @@ import (
|
|||||||
|
|
||||||
"github.com/HyNetwork/hysteria/cmd/auth"
|
"github.com/HyNetwork/hysteria/cmd/auth"
|
||||||
"github.com/HyNetwork/hysteria/pkg/acl"
|
"github.com/HyNetwork/hysteria/pkg/acl"
|
||||||
hyCongestion "github.com/HyNetwork/hysteria/pkg/congestion"
|
|
||||||
"github.com/HyNetwork/hysteria/pkg/core"
|
"github.com/HyNetwork/hysteria/pkg/core"
|
||||||
"github.com/HyNetwork/hysteria/pkg/obfs"
|
"github.com/HyNetwork/hysteria/pkg/obfs"
|
||||||
"github.com/HyNetwork/hysteria/pkg/pmtud_fix"
|
"github.com/HyNetwork/hysteria/pkg/pmtud_fix"
|
||||||
"github.com/HyNetwork/hysteria/pkg/sockopt"
|
"github.com/HyNetwork/hysteria/pkg/sockopt"
|
||||||
"github.com/HyNetwork/hysteria/pkg/transport"
|
"github.com/HyNetwork/hysteria/pkg/transport"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
"github.com/lucas-clemente/quic-go/congestion"
|
|
||||||
"github.com/oschwald/geoip2-golang"
|
"github.com/oschwald/geoip2-golang"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
@ -224,10 +222,7 @@ func server(config *serverConfig) {
|
|||||||
}
|
}
|
||||||
up, down, _ := config.Speed()
|
up, down, _ := config.Speed()
|
||||||
server, err := core.NewServer(config.Listen, config.Protocol, tlsConfig, quicConfig, transport.DefaultServerTransport,
|
server, err := core.NewServer(config.Listen, config.Protocol, tlsConfig, quicConfig, transport.DefaultServerTransport,
|
||||||
up, down,
|
up, down, config.DisableUDP, aclEngine, obfuscator, connectFunc, disconnectFunc,
|
||||||
func(refBPS uint64) congestion.CongestionControl {
|
|
||||||
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
|
||||||
}, config.DisableUDP, aclEngine, obfuscator, connectFunc, disconnectFunc,
|
|
||||||
tcpRequestFunc, tcpErrorFunc, udpRequestFunc, udpErrorFunc, promReg)
|
tcpRequestFunc, tcpErrorFunc, udpRequestFunc, udpErrorFunc, promReg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("error", err).Fatal("Failed to initialize server")
|
logrus.WithField("error", err).Fatal("Failed to initialize server")
|
||||||
|
@ -30,9 +30,9 @@ type pktInfo struct {
|
|||||||
LossCount uint64
|
LossCount uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBrutalSender(bps congestion.ByteCount) *BrutalSender {
|
func NewBrutalSender(bps uint64) *BrutalSender {
|
||||||
bs := &BrutalSender{
|
bs := &BrutalSender{
|
||||||
bps: bps,
|
bps: congestion.ByteCount(bps),
|
||||||
maxDatagramSize: initMaxDatagramSize,
|
maxDatagramSize: initMaxDatagramSize,
|
||||||
ackRate: 1,
|
ackRate: 1,
|
||||||
}
|
}
|
||||||
|
@ -12,26 +12,24 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/HyNetwork/hysteria/pkg/congestion"
|
||||||
|
|
||||||
"github.com/HyNetwork/hysteria/pkg/obfs"
|
"github.com/HyNetwork/hysteria/pkg/obfs"
|
||||||
"github.com/HyNetwork/hysteria/pkg/pmtud_fix"
|
"github.com/HyNetwork/hysteria/pkg/pmtud_fix"
|
||||||
"github.com/HyNetwork/hysteria/pkg/transport"
|
"github.com/HyNetwork/hysteria/pkg/transport"
|
||||||
"github.com/HyNetwork/hysteria/pkg/utils"
|
"github.com/HyNetwork/hysteria/pkg/utils"
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
"github.com/lucas-clemente/quic-go/congestion"
|
|
||||||
"github.com/lunixbochs/struc"
|
"github.com/lunixbochs/struc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrClosed = errors.New("closed")
|
var ErrClosed = errors.New("closed")
|
||||||
|
|
||||||
type CongestionFactory func(refBPS uint64) congestion.CongestionControl
|
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
transport *transport.ClientTransport
|
transport *transport.ClientTransport
|
||||||
serverAddr string
|
serverAddr string
|
||||||
protocol string
|
protocol string
|
||||||
sendBPS, recvBPS uint64
|
sendBPS, recvBPS uint64
|
||||||
auth []byte
|
auth []byte
|
||||||
congestionFactory CongestionFactory
|
|
||||||
obfuscator obfs.Obfuscator
|
obfuscator obfs.Obfuscator
|
||||||
|
|
||||||
tlsConfig *tls.Config
|
tlsConfig *tls.Config
|
||||||
@ -49,8 +47,8 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config,
|
func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config,
|
||||||
transport *transport.ClientTransport, sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory,
|
transport *transport.ClientTransport, sendBPS uint64, recvBPS uint64, obfuscator obfs.Obfuscator,
|
||||||
obfuscator obfs.Obfuscator, quicReconnectFunc func(err error),
|
quicReconnectFunc func(err error),
|
||||||
) (*Client, error) {
|
) (*Client, error) {
|
||||||
quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery
|
quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery
|
||||||
c := &Client{
|
c := &Client{
|
||||||
@ -60,7 +58,6 @@ func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.C
|
|||||||
sendBPS: sendBPS,
|
sendBPS: sendBPS,
|
||||||
recvBPS: recvBPS,
|
recvBPS: recvBPS,
|
||||||
auth: auth,
|
auth: auth,
|
||||||
congestionFactory: congestionFactory,
|
|
||||||
obfuscator: obfuscator,
|
obfuscator: obfuscator,
|
||||||
tlsConfig: tlsConfig,
|
tlsConfig: tlsConfig,
|
||||||
quicConfig: quicConfig,
|
quicConfig: quicConfig,
|
||||||
@ -125,8 +122,8 @@ func (c *Client) handleControlStream(qs quic.Connection, stream quic.Stream) (bo
|
|||||||
return false, "", err
|
return false, "", err
|
||||||
}
|
}
|
||||||
// Set the congestion accordingly
|
// Set the congestion accordingly
|
||||||
if sh.OK && c.congestionFactory != nil {
|
if sh.OK {
|
||||||
qs.SetCongestionControl(c.congestionFactory(sh.Rate.RecvBPS))
|
qs.SetCongestionControl(congestion.NewBrutalSender(sh.Rate.RecvBPS))
|
||||||
}
|
}
|
||||||
return sh.OK, sh.Message, nil
|
return sh.OK, sh.Message, nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/HyNetwork/hysteria/pkg/congestion"
|
||||||
|
|
||||||
"github.com/HyNetwork/hysteria/pkg/acl"
|
"github.com/HyNetwork/hysteria/pkg/acl"
|
||||||
"github.com/HyNetwork/hysteria/pkg/obfs"
|
"github.com/HyNetwork/hysteria/pkg/obfs"
|
||||||
"github.com/HyNetwork/hysteria/pkg/pmtud_fix"
|
"github.com/HyNetwork/hysteria/pkg/pmtud_fix"
|
||||||
@ -28,7 +30,6 @@ type (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
transport *transport.ServerTransport
|
transport *transport.ServerTransport
|
||||||
sendBPS, recvBPS uint64
|
sendBPS, recvBPS uint64
|
||||||
congestionFactory CongestionFactory
|
|
||||||
disableUDP bool
|
disableUDP bool
|
||||||
aclEngine *acl.Engine
|
aclEngine *acl.Engine
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ type Server struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(addr string, protocol string, tlsConfig *tls.Config, quicConfig *quic.Config, transport *transport.ServerTransport,
|
func NewServer(addr string, protocol string, tlsConfig *tls.Config, quicConfig *quic.Config, transport *transport.ServerTransport,
|
||||||
sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory, disableUDP bool, aclEngine *acl.Engine,
|
sendBPS uint64, recvBPS uint64, disableUDP bool, aclEngine *acl.Engine,
|
||||||
obfuscator obfs.Obfuscator, connectFunc ConnectFunc, disconnectFunc DisconnectFunc,
|
obfuscator obfs.Obfuscator, connectFunc ConnectFunc, disconnectFunc DisconnectFunc,
|
||||||
tcpRequestFunc TCPRequestFunc, tcpErrorFunc TCPErrorFunc,
|
tcpRequestFunc TCPRequestFunc, tcpErrorFunc TCPErrorFunc,
|
||||||
udpRequestFunc UDPRequestFunc, udpErrorFunc UDPErrorFunc, promRegistry *prometheus.Registry,
|
udpRequestFunc UDPRequestFunc, udpErrorFunc UDPErrorFunc, promRegistry *prometheus.Registry,
|
||||||
@ -61,7 +62,6 @@ func NewServer(addr string, protocol string, tlsConfig *tls.Config, quicConfig *
|
|||||||
transport: transport,
|
transport: transport,
|
||||||
sendBPS: sendBPS,
|
sendBPS: sendBPS,
|
||||||
recvBPS: recvBPS,
|
recvBPS: recvBPS,
|
||||||
congestionFactory: congestionFactory,
|
|
||||||
disableUDP: disableUDP,
|
disableUDP: disableUDP,
|
||||||
aclEngine: aclEngine,
|
aclEngine: aclEngine,
|
||||||
connectFunc: connectFunc,
|
connectFunc: connectFunc,
|
||||||
@ -172,8 +172,8 @@ func (s *Server) handleControlStream(cs quic.Connection, stream quic.Stream) ([]
|
|||||||
return nil, false, false, err
|
return nil, false, false, err
|
||||||
}
|
}
|
||||||
// Set the congestion accordingly
|
// Set the congestion accordingly
|
||||||
if ok && s.congestionFactory != nil {
|
if ok {
|
||||||
cs.SetCongestionControl(s.congestionFactory(serverSendBPS))
|
cs.SetCongestionControl(congestion.NewBrutalSender(serverSendBPS))
|
||||||
}
|
}
|
||||||
return ch.Auth, ok, vb[0] == protocolVersionV2, nil
|
return ch.Auth, ok, vb[0] == protocolVersionV2, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user