From 582ac28728d2366bdd2a335a178c9949fd9c0624 Mon Sep 17 00:00:00 2001 From: H1JK Date: Fri, 8 Dec 2023 21:22:20 +0800 Subject: [PATCH] chore: Update bandwidth convertor Sync with https://github.com/apernet/hysteria/commit/6d6a26b3995dec982d5989ef738796a23a0a6495 --- adapter/outbound/util.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/adapter/outbound/util.go b/adapter/outbound/util.go index ce9e5f65..2c85c7c8 100644 --- a/adapter/outbound/util.go +++ b/adapter/outbound/util.go @@ -140,24 +140,25 @@ func StringToBps(s string) uint64 { if m == nil { return 0 } - var n uint64 + var n uint64 = 1 switch m[2] { - case "K": - n = 1 << 10 - case "M": - n = 1 << 20 - case "G": - n = 1 << 30 case "T": - n = 1 << 40 - default: - n = 1 + n *= 1000 + fallthrough + case "G": + n *= 1000 + fallthrough + case "M": + n *= 1000 + fallthrough + case "K": + n *= 1000 } v, _ := strconv.ParseUint(m[1], 10, 64) - n = v * n + n *= v if m[3] == "b" { // Bits, need to convert to bytes - n = n >> 3 + n /= 8 } return n }