Release 1.2.0 Windows amd64 with Hysteria 2
This commit is contained in:
@@ -11,7 +11,8 @@ import (
|
||||
type Protocol string
|
||||
|
||||
const (
|
||||
ProtocolNaive Protocol = "naive"
|
||||
ProtocolNaive Protocol = "naive"
|
||||
ProtocolHysteria2 Protocol = "hysteria2"
|
||||
)
|
||||
|
||||
// Config is the top-level client configuration.
|
||||
@@ -161,8 +162,10 @@ func (c *Config) Validate() error {
|
||||
return fmt.Errorf("config: profile[%d] missing name", i)
|
||||
}
|
||||
switch p.Protocol {
|
||||
case ProtocolNaive:
|
||||
case ProtocolNaive, ProtocolHysteria2:
|
||||
// Proxy may be empty until the user pastes a share link in the UI.
|
||||
case "":
|
||||
c.Profiles[i].Protocol = ProtocolNaive
|
||||
default:
|
||||
return fmt.Errorf("config: profile %q: unsupported protocol %q", p.Name, p.Protocol)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package config
|
||||
|
||||
import "strings"
|
||||
|
||||
// DetectProtocol infers protocol from a share/proxy URI.
|
||||
func DetectProtocol(raw string) Protocol {
|
||||
lower := strings.ToLower(strings.TrimSpace(raw))
|
||||
switch {
|
||||
case strings.HasPrefix(lower, "hysteria2://"), strings.HasPrefix(lower, "hy2://"):
|
||||
return ProtocolHysteria2
|
||||
case strings.HasPrefix(lower, "naive+"), strings.HasPrefix(lower, "naive://"),
|
||||
strings.HasPrefix(lower, "https://"), strings.HasPrefix(lower, "quic://"),
|
||||
strings.HasPrefix(lower, "http://"):
|
||||
return ProtocolNaive
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -60,16 +60,29 @@ func (c *Config) SetActive(name string) error {
|
||||
|
||||
// UpsertProfile creates or updates a profile by name.
|
||||
func (c *Config) UpsertProfile(name, proxy string) error {
|
||||
return c.UpsertProfileWithProtocol(name, proxy, "")
|
||||
}
|
||||
|
||||
// UpsertProfileWithProtocol creates/updates a profile and optionally sets protocol.
|
||||
func (c *Config) UpsertProfileWithProtocol(name, proxy string, proto Protocol) error {
|
||||
name = strings.TrimSpace(name)
|
||||
if name == "" {
|
||||
return fmt.Errorf("имя профиля пустое")
|
||||
}
|
||||
proxy = strings.TrimSpace(proxy)
|
||||
if proto == "" {
|
||||
proto = DetectProtocol(proxy)
|
||||
}
|
||||
if proto == "" {
|
||||
proto = ProtocolNaive
|
||||
}
|
||||
|
||||
for i := range c.Profiles {
|
||||
if c.Profiles[i].Name == name {
|
||||
c.Profiles[i].Proxy = proxy
|
||||
if c.Profiles[i].Protocol == "" {
|
||||
if proto != "" {
|
||||
c.Profiles[i].Protocol = proto
|
||||
} else if c.Profiles[i].Protocol == "" {
|
||||
c.Profiles[i].Protocol = ProtocolNaive
|
||||
}
|
||||
if len(c.Profiles[i].Listen) == 0 {
|
||||
@@ -82,7 +95,7 @@ func (c *Config) UpsertProfile(name, proxy string) error {
|
||||
|
||||
c.Profiles = append(c.Profiles, Profile{
|
||||
Name: name,
|
||||
Protocol: ProtocolNaive,
|
||||
Protocol: proto,
|
||||
Proxy: proxy,
|
||||
Listen: defaultListen(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user