Release 1.2.0 Windows amd64 with Hysteria 2
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"time"
|
||||
|
||||
"vpnclient/internal/config"
|
||||
"vpnclient/internal/linknorm"
|
||||
"vpnclient/internal/protocols/hysteria2"
|
||||
"vpnclient/internal/protocols/naive"
|
||||
"vpnclient/internal/sysproxy"
|
||||
)
|
||||
@@ -200,13 +202,20 @@ func (m *Manager) SetSystemProxy(enabled bool) {
|
||||
func (m *Manager) UpdateProxyURI(proxy string) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
normalized, err := naive.NormalizeProxyURI(proxy)
|
||||
active, err := m.cfg.ActiveProfile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
normalized, proto, _, err := linknorm.Normalize(active.Protocol, proxy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := m.cfg.SetActiveProxy(normalized); err != nil {
|
||||
return err
|
||||
}
|
||||
if proto != "" {
|
||||
_ = m.cfg.UpsertProfileWithProtocol(m.cfg.Active, normalized, proto)
|
||||
}
|
||||
return config.Save(m.cfgPath, *m.cfg)
|
||||
}
|
||||
|
||||
@@ -229,14 +238,16 @@ func (m *Manager) SaveProfile(name, proxy string) error {
|
||||
return fmt.Errorf("сначала отключитесь")
|
||||
}
|
||||
proxy = strings.TrimSpace(proxy)
|
||||
var proto config.Protocol
|
||||
if proxy != "" {
|
||||
normalized, err := naive.NormalizeProxyURI(proxy)
|
||||
normalized, detected, _, err := linknorm.Normalize("", proxy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proxy = normalized
|
||||
proto = detected
|
||||
}
|
||||
if err := m.cfg.UpsertProfile(name, proxy); err != nil {
|
||||
if err := m.cfg.UpsertProfileWithProtocol(name, proxy, proto); err != nil {
|
||||
return err
|
||||
}
|
||||
return config.Save(m.cfgPath, *m.cfg)
|
||||
@@ -254,12 +265,18 @@ func (m *Manager) SaveActiveProfile(name, proxy string) error {
|
||||
return fmt.Errorf("имя профиля пустое")
|
||||
}
|
||||
proxy = strings.TrimSpace(proxy)
|
||||
var proto config.Protocol
|
||||
if proxy != "" {
|
||||
normalized, err := naive.NormalizeProxyURI(proxy)
|
||||
activeProto := config.Protocol("")
|
||||
if p, err := m.cfg.ActiveProfile(); err == nil {
|
||||
activeProto = p.Protocol
|
||||
}
|
||||
normalized, detected, _, err := linknorm.Normalize(activeProto, proxy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proxy = normalized
|
||||
proto = detected
|
||||
}
|
||||
|
||||
active := m.cfg.Active
|
||||
@@ -279,7 +296,7 @@ func (m *Manager) SaveActiveProfile(name, proxy string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := m.cfg.SetActiveProxy(proxy); err != nil {
|
||||
if err := m.cfg.UpsertProfileWithProtocol(name, proxy, proto); err != nil {
|
||||
return err
|
||||
}
|
||||
return config.Save(m.cfgPath, *m.cfg)
|
||||
@@ -330,9 +347,42 @@ func (m *Manager) Reload() error {
|
||||
|
||||
func (m *Manager) newEngine(p config.Protocol) (Engine, error) {
|
||||
switch p {
|
||||
case config.ProtocolNaive:
|
||||
case config.ProtocolNaive, "":
|
||||
return naive.New(m.stderr), nil
|
||||
case config.ProtocolHysteria2:
|
||||
return hysteria2.New(m.stderr), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported protocol %q", p)
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureCore downloads the binary required by the active (or given) protocol.
|
||||
func (m *Manager) EnsureCore(proto config.Protocol) (string, error) {
|
||||
if proto == "" {
|
||||
if p, err := m.cfg.ActiveProfile(); err == nil {
|
||||
proto = p.Protocol
|
||||
}
|
||||
}
|
||||
switch proto {
|
||||
case config.ProtocolHysteria2:
|
||||
return hysteria2.EnsureBinary(m.binDir)
|
||||
default:
|
||||
return naive.EnsureBinary(m.binDir)
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureAllCores installs naive + hysteria2 cores.
|
||||
func (m *Manager) EnsureAllCores() (map[string]string, error) {
|
||||
out := map[string]string{}
|
||||
p1, err := naive.EnsureBinary(m.binDir)
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("naive: %w", err)
|
||||
}
|
||||
out["naive"] = p1
|
||||
p2, err := hysteria2.EnsureBinary(m.binDir)
|
||||
if err != nil {
|
||||
return out, fmt.Errorf("hysteria2: %w", err)
|
||||
}
|
||||
out["hysteria2"] = p2
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user