mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-07-25 08:38:14 +03:00
Add MTProxy, MASQUE, VPN, Link parser. Update AmneziaWG. Remove Tunneling
This commit is contained in:
61
parser/link/hysteria2.go
Normal file
61
parser/link/hysteria2.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package link
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/sagernet/sing-box/common"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
)
|
||||
|
||||
func parseHysteria2Link(link string) (option.Outbound, error) {
|
||||
linkURL, err := url.Parse(link)
|
||||
if err != nil {
|
||||
return option.Outbound{}, err
|
||||
}
|
||||
var options option.Hysteria2OutboundOptions
|
||||
TLSOptions := option.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ECH: &option.OutboundECHOptions{},
|
||||
UTLS: &option.OutboundUTLSOptions{},
|
||||
Reality: &option.OutboundRealityOptions{},
|
||||
}
|
||||
Obfs := &option.Hysteria2Obfs{}
|
||||
options.ServerPort = uint16(443)
|
||||
options.Server = linkURL.Hostname()
|
||||
TLSOptions.ServerName = linkURL.Hostname()
|
||||
if linkURL.User != nil {
|
||||
options.Password = linkURL.User.Username()
|
||||
}
|
||||
if linkURL.Port() != "" {
|
||||
options.ServerPort = common.StringToType[uint16](linkURL.Port())
|
||||
}
|
||||
for key, values := range linkURL.Query() {
|
||||
value := values[0]
|
||||
switch key {
|
||||
case "up":
|
||||
options.UpMbps, _ = strconv.Atoi(value)
|
||||
case "down":
|
||||
options.DownMbps, _ = strconv.Atoi(value)
|
||||
case "obfs":
|
||||
if value == "salamander" {
|
||||
Obfs.Type = "salamander"
|
||||
options.Obfs = Obfs
|
||||
}
|
||||
case "obfs-password":
|
||||
Obfs.Password = value
|
||||
case "insecure", "skip-cert-verify":
|
||||
if value == "1" || value == "true" {
|
||||
TLSOptions.Insecure = true
|
||||
}
|
||||
}
|
||||
}
|
||||
outbound := option.Outbound{
|
||||
Type: C.TypeHysteria2,
|
||||
Tag: linkURL.Fragment,
|
||||
}
|
||||
options.TLS = &TLSOptions
|
||||
outbound.Options = &options
|
||||
return outbound, nil
|
||||
}
|
||||
Reference in New Issue
Block a user