From 743df5373b02c8e08429a7507ebe1d3e40e381d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 17 Sep 2023 00:25:53 +0800 Subject: [PATCH] Fix hysteria2 mbps calculation --- inbound/hysteria2.go | 5 +++-- outbound/hysteria2.go | 5 +++-- test/go.mod | 4 ++++ test/go.sum | 7 +++++-- test/hysteria2_test.go | 6 +++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/inbound/hysteria2.go b/inbound/hysteria2.go index f2726e67..82e2f0b7 100644 --- a/inbound/hysteria2.go +++ b/inbound/hysteria2.go @@ -14,6 +14,7 @@ import ( C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" + "github.com/sagernet/sing-box/transport/hysteria" "github.com/sagernet/sing-quic/hysteria2" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/auth" @@ -88,8 +89,8 @@ func NewHysteria2(ctx context.Context, router adapter.Router, logger log.Context service, err := hysteria2.NewService[int](hysteria2.ServiceOptions{ Context: ctx, Logger: logger, - SendBPS: uint64(options.UpMbps * 1024 * 1024), - ReceiveBPS: uint64(options.DownMbps * 1024 * 1024), + SendBPS: uint64(options.UpMbps * hysteria.MbpsToBps), + ReceiveBPS: uint64(options.DownMbps * hysteria.MbpsToBps), SalamanderPassword: salamanderPassword, TLSConfig: tlsConfig, IgnoreClientBandwidth: options.IgnoreClientBandwidth, diff --git a/outbound/hysteria2.go b/outbound/hysteria2.go index 9bd4b310..120865a9 100644 --- a/outbound/hysteria2.go +++ b/outbound/hysteria2.go @@ -13,6 +13,7 @@ import ( C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-box/option" + "github.com/sagernet/sing-box/transport/hysteria" "github.com/sagernet/sing-quic/hysteria2" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/bufio" @@ -61,8 +62,8 @@ func NewHysteria2(ctx context.Context, router adapter.Router, logger log.Context Context: ctx, Dialer: outboundDialer, ServerAddress: options.ServerOptions.Build(), - SendBPS: uint64(options.UpMbps * 1024 * 1024), - ReceiveBPS: uint64(options.DownMbps * 1024 * 1024), + SendBPS: uint64(options.UpMbps * hysteria.MbpsToBps), + ReceiveBPS: uint64(options.DownMbps * hysteria.MbpsToBps), SalamanderPassword: salamanderPassword, Password: options.Password, TLSConfig: tlsConfig, diff --git a/test/go.mod b/test/go.mod index d8f504de..eb61c776 100644 --- a/test/go.mod +++ b/test/go.mod @@ -6,6 +6,8 @@ require github.com/sagernet/sing-box v0.0.0 replace github.com/sagernet/sing-box => ../ +replace github.com/sagernet/sing-quic => ../../sing-quic + require ( github.com/docker/docker v24.0.5+incompatible github.com/docker/go-connections v0.4.0 @@ -49,6 +51,8 @@ require ( github.com/josharian/native v1.1.0 // indirect github.com/klauspost/compress v1.15.15 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect + github.com/libdns/alidns v1.0.3 // indirect + github.com/libdns/cloudflare v0.1.0 // indirect github.com/libdns/libdns v0.2.1 // indirect github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/mholt/acmez v1.2.0 // indirect diff --git a/test/go.sum b/test/go.sum index 2d376b85..56accdf2 100644 --- a/test/go.sum +++ b/test/go.sum @@ -77,6 +77,11 @@ github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuOb github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/libdns/alidns v1.0.3 h1:LFHuGnbseq5+HCeGa1aW8awyX/4M2psB9962fdD2+yQ= +github.com/libdns/alidns v1.0.3/go.mod h1:e18uAG6GanfRhcJj6/tps2rCMzQJaYVcGKT+ELjdjGE= +github.com/libdns/cloudflare v0.1.0 h1:93WkJaGaiXCe353LHEP36kAWCUw0YjFqwhkBkU2/iic= +github.com/libdns/cloudflare v0.1.0/go.mod h1:a44IP6J1YH6nvcNl1PverfJviADgXUnsozR3a7vBKN8= +github.com/libdns/libdns v0.2.0/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40= github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis= github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40= github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= @@ -133,8 +138,6 @@ github.com/sagernet/sing-dns v0.1.9-0.20230911082806-425022bdc92b h1:m/UWg2voyb9 github.com/sagernet/sing-dns v0.1.9-0.20230911082806-425022bdc92b/go.mod h1:Kg98PBJEg/08jsNFtmZWmPomhskn9Ausn50ecNm4M+8= github.com/sagernet/sing-mux v0.1.3-0.20230908032617-759a1886a400 h1:LtpYd5c5AJtUSxjyH4KjUS8HT+2XgilyozjbCq/x3EM= github.com/sagernet/sing-mux v0.1.3-0.20230908032617-759a1886a400/go.mod h1:TKxqIvfQQgd36jp2tzsPavGjYTVZilV+atip1cssjIY= -github.com/sagernet/sing-quic v0.0.0-20230915093242-b55f3531e703 h1:BbJZ5RkY3jQk5P9G5Ra0VhmDNKdT0aIP1FszEDyQL+o= -github.com/sagernet/sing-quic v0.0.0-20230915093242-b55f3531e703/go.mod h1:Mh5Senu4XDuX+RxSPQEoUB0j6kVmGais2h62Cnfj6Xk= github.com/sagernet/sing-shadowsocks v0.2.5-0.20230907005610-126234728ca0 h1:9wHYWxH+fcs01PM2+DylA8LNNY3ElnZykQo9rysng8U= github.com/sagernet/sing-shadowsocks v0.2.5-0.20230907005610-126234728ca0/go.mod h1:80fNKP0wnqlu85GZXV1H1vDPC/2t+dQbFggOw4XuFUM= github.com/sagernet/sing-shadowsocks2 v0.1.4-0.20230907005906-5d2917b29248 h1:JTFfy/LDmVFEK4KZJEujmC1iO8+aoF4unYhhZZRzRq4= diff --git a/test/hysteria2_test.go b/test/hysteria2_test.go index d659f536..695e598b 100644 --- a/test/hysteria2_test.go +++ b/test/hysteria2_test.go @@ -46,7 +46,9 @@ func testHysteria2Self(t *testing.T, salamanderPassword string) { Listen: option.NewListenAddress(netip.IPv4Unspecified()), ListenPort: serverPort, }, - Obfs: obfs, + UpMbps: 100, + DownMbps: 100, + Obfs: obfs, Users: []option.Hysteria2User{{ Password: "password", }}, @@ -71,6 +73,8 @@ func testHysteria2Self(t *testing.T, salamanderPassword string) { Server: "127.0.0.1", ServerPort: serverPort, }, + UpMbps: 100, + DownMbps: 100, Obfs: obfs, Password: "password", TLS: &option.OutboundTLSOptions{