feat: inbound support Hysteria2

This commit is contained in:
wwqgtxx
2023-09-21 14:52:26 +08:00
parent 6c3b973748
commit 233eeb0b38
8 changed files with 315 additions and 6 deletions

View File

@ -117,12 +117,12 @@ type HysteriaOption struct {
func (c *HysteriaOption) Speed() (uint64, uint64, error) {
var up, down uint64
up = stringToBps(c.Up)
up = StringToBps(c.Up)
if up == 0 {
return 0, 0, fmt.Errorf("invaild upload speed: %s", c.Up)
}
down = stringToBps(c.Down)
down = StringToBps(c.Down)
if down == 0 {
return 0, 0, fmt.Errorf("invaild download speed: %s", c.Down)
}

View File

@ -185,8 +185,8 @@ func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
Context: context.TODO(),
Dialer: singDialer,
ServerAddress: M.ParseSocksaddrHostPort(option.Server, uint16(option.Port)),
SendBPS: stringToBps(option.Up),
ReceiveBPS: stringToBps(option.Down),
SendBPS: StringToBps(option.Up),
ReceiveBPS: StringToBps(option.Down),
SalamanderPassword: salamanderPassword,
Password: option.Password,
TLSConfig: tlsConfig,

View File

@ -126,14 +126,14 @@ func safeConnClose(c net.Conn, err error) {
var rateStringRegexp = regexp.MustCompile(`^(\d+)\s*([KMGT]?)([Bb])ps$`)
func stringToBps(s string) uint64 {
func StringToBps(s string) uint64 {
if s == "" {
return 0
}
// when have not unit, use Mbps
if v, err := strconv.Atoi(s); err == nil {
return stringToBps(fmt.Sprintf("%d Mbps", v))
return StringToBps(fmt.Sprintf("%d Mbps", v))
}
m := rateStringRegexp.FindStringSubmatch(s)