Release 1.3.0: Hysteria2 BBR/Salamander/masquerade options and subscription URL import.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"vpnclient/internal/linknorm"
|
||||
"vpnclient/internal/protocols/hysteria2"
|
||||
"vpnclient/internal/protocols/naive"
|
||||
"vpnclient/internal/subscription"
|
||||
"vpnclient/internal/sysproxy"
|
||||
)
|
||||
|
||||
@@ -250,6 +251,9 @@ func (m *Manager) SaveProfile(name, proxy string) error {
|
||||
if err := m.cfg.UpsertProfileWithProtocol(name, proxy, proto); err != nil {
|
||||
return err
|
||||
}
|
||||
if p, err := m.cfg.ActiveProfile(); err == nil {
|
||||
hysteria2.EnrichProfile(p)
|
||||
}
|
||||
return config.Save(m.cfgPath, *m.cfg)
|
||||
}
|
||||
|
||||
@@ -299,6 +303,9 @@ func (m *Manager) SaveActiveProfile(name, proxy string) error {
|
||||
if err := m.cfg.UpsertProfileWithProtocol(name, proxy, proto); err != nil {
|
||||
return err
|
||||
}
|
||||
if p, err := m.cfg.ActiveProfile(); err == nil {
|
||||
hysteria2.EnrichProfile(p)
|
||||
}
|
||||
return config.Save(m.cfgPath, *m.cfg)
|
||||
}
|
||||
|
||||
@@ -320,6 +327,110 @@ func (m *Manager) Profiles() []config.ProfileInfo {
|
||||
return m.cfg.ListProfiles()
|
||||
}
|
||||
|
||||
// Hy2Options are editable Hysteria 2 extras for the active profile.
|
||||
type Hy2Options struct {
|
||||
Congestion string `json:"congestion"`
|
||||
BBRProfile string `json:"bbr_profile"`
|
||||
BandwidthUp string `json:"bandwidth_up"`
|
||||
BandwidthDown string `json:"bandwidth_down"`
|
||||
Obfs string `json:"obfs"`
|
||||
ObfsPassword string `json:"obfs_password"`
|
||||
SNI string `json:"sni"`
|
||||
Insecure bool `json:"insecure"`
|
||||
PinSHA256 string `json:"pin_sha256"`
|
||||
FastOpen bool `json:"fast_open"`
|
||||
Lazy bool `json:"lazy"`
|
||||
HopInterval string `json:"hop_interval"`
|
||||
}
|
||||
|
||||
func (m *Manager) ActiveHy2Options() Hy2Options {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
p, err := m.cfg.ActiveProfile()
|
||||
if err != nil {
|
||||
return Hy2Options{Congestion: "bbr", BBRProfile: "standard"}
|
||||
}
|
||||
return Hy2Options{
|
||||
Congestion: p.Hy2Congestion,
|
||||
BBRProfile: p.Hy2BBRProfile,
|
||||
BandwidthUp: p.Hy2BandwidthUp,
|
||||
BandwidthDown: p.Hy2BandwidthDown,
|
||||
Obfs: p.Hy2Obfs,
|
||||
ObfsPassword: p.Hy2ObfsPassword,
|
||||
SNI: p.Hy2SNI,
|
||||
Insecure: p.Hy2Insecure,
|
||||
PinSHA256: p.Hy2PinSHA256,
|
||||
FastOpen: p.Hy2FastOpen,
|
||||
Lazy: p.Hy2Lazy,
|
||||
HopInterval: p.Hy2HopInterval,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) SaveHy2Options(opts Hy2Options) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.engine != nil && m.engine.Running() {
|
||||
return fmt.Errorf("сначала отключитесь")
|
||||
}
|
||||
p, err := m.cfg.ActiveProfile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Protocol = config.ProtocolHysteria2
|
||||
p.Hy2Congestion = strings.TrimSpace(opts.Congestion)
|
||||
p.Hy2BBRProfile = strings.TrimSpace(opts.BBRProfile)
|
||||
p.Hy2BandwidthUp = strings.TrimSpace(opts.BandwidthUp)
|
||||
p.Hy2BandwidthDown = strings.TrimSpace(opts.BandwidthDown)
|
||||
p.Hy2Obfs = strings.TrimSpace(opts.Obfs)
|
||||
p.Hy2ObfsPassword = strings.TrimSpace(opts.ObfsPassword)
|
||||
p.Hy2SNI = strings.TrimSpace(opts.SNI)
|
||||
p.Hy2Insecure = opts.Insecure
|
||||
p.Hy2PinSHA256 = strings.TrimSpace(opts.PinSHA256)
|
||||
p.Hy2FastOpen = opts.FastOpen
|
||||
p.Hy2Lazy = opts.Lazy
|
||||
p.Hy2HopInterval = strings.TrimSpace(opts.HopInterval)
|
||||
return config.Save(m.cfgPath, *m.cfg)
|
||||
}
|
||||
|
||||
func (m *Manager) SubscriptionURL() string {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
return m.cfg.SubscriptionURL
|
||||
}
|
||||
|
||||
func (m *Manager) ImportSubscription(rawURL string) (int, error) {
|
||||
m.mu.Lock()
|
||||
if m.engine != nil && m.engine.Running() {
|
||||
m.mu.Unlock()
|
||||
return 0, fmt.Errorf("сначала отключитесь")
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)
|
||||
defer cancel()
|
||||
items, err := subscription.Fetch(ctx, rawURL)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.cfg.SubscriptionURL = strings.TrimSpace(rawURL)
|
||||
for _, it := range items {
|
||||
_ = m.cfg.UpsertProfileWithProtocol(it.Name, it.URI, it.Protocol)
|
||||
for i := range m.cfg.Profiles {
|
||||
if m.cfg.Profiles[i].Name == it.Name {
|
||||
hysteria2.EnrichProfile(&m.cfg.Profiles[i])
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := config.Save(m.cfgPath, *m.cfg); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(items), nil
|
||||
}
|
||||
|
||||
func (m *Manager) SaveConfig() error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user