Change warp generation
This commit is contained in:
@@ -388,13 +388,13 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
|
||||
var outbounds []option.Outbound
|
||||
var tags []string
|
||||
if opt.WarpOptions != nil && (opt.WarpOptions.Mode == "proxy_over_warp" || opt.WarpOptions.Mode == "warp_over_proxy") {
|
||||
out, err := generateWarpSingbox(opt.WarpOptions.WireguardConfig, opt.WarpOptions.CleanIP, opt.WarpOptions.CleanPort, opt.WarpOptions.FakePackets, opt.WarpOptions.FakePacketSize, opt.WarpOptions.FakePacketDelay)
|
||||
if opt.Warp.EnableWarp && (opt.Warp.Mode == "proxy_over_warp" || opt.Warp.Mode == "warp_over_proxy") {
|
||||
out, err := generateWarpSingbox(opt.Warp.WireguardConfig.ToWireguardConfig(), opt.Warp.CleanIP, opt.Warp.CleanPort, opt.Warp.FakePackets, opt.Warp.FakePacketSize, opt.Warp.FakePacketDelay)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate warp config: %v", err)
|
||||
}
|
||||
out.Tag = "Hiddify Warp Config"
|
||||
if opt.WarpOptions.Mode == "warp_over_proxy" {
|
||||
if opt.Warp.Mode == "warp_over_proxy" {
|
||||
out.WireGuardOptions.Detour = "select"
|
||||
}
|
||||
outbounds = append(outbounds, *out)
|
||||
@@ -515,7 +515,7 @@ func BuildConfig(opt ConfigOptions, input option.Options) (*option.Options, erro
|
||||
}
|
||||
|
||||
func patchHiddifyWarpFromConfig(out option.Outbound, opt ConfigOptions) option.Outbound {
|
||||
if opt.WarpOptions != nil && opt.WarpOptions.Mode == "proxy_over_warp" {
|
||||
if opt.Warp.EnableWarp && opt.Warp.Mode == "proxy_over_warp" {
|
||||
out.DirectOptions.Detour = "Hiddify Warp Config"
|
||||
out.HTTPOptions.Detour = "Hiddify Warp Config"
|
||||
out.Hysteria2Options.Detour = "Hiddify Warp Config"
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/bepass-org/wireguard-go/warp"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
dns "github.com/sagernet/sing-dns"
|
||||
)
|
||||
|
||||
type ConfigOptions struct {
|
||||
LogLevel string `json:"log-level"`
|
||||
EnableClashApi bool `json:"enable-clash-api"`
|
||||
ClashApiPort uint16 `json:"clash-api-port"`
|
||||
GeoIPPath string `json:"geoip-path"`
|
||||
GeoSitePath string `json:"geosite-path"`
|
||||
Rules []Rule `json:"rules"`
|
||||
LogLevel string `json:"log-level"`
|
||||
EnableClashApi bool `json:"enable-clash-api"`
|
||||
ClashApiPort uint16 `json:"clash-api-port"`
|
||||
GeoIPPath string `json:"geoip-path"`
|
||||
GeoSitePath string `json:"geosite-path"`
|
||||
Rules []Rule `json:"rules"`
|
||||
Warp WarpOptions `json:"warp"`
|
||||
DNSOptions
|
||||
InboundOptions
|
||||
URLTestOptions
|
||||
RouteOptions
|
||||
MuxOptions
|
||||
TLSTricks
|
||||
*WarpOptions
|
||||
}
|
||||
|
||||
type DNSOptions struct {
|
||||
@@ -73,14 +72,15 @@ type MuxOptions struct {
|
||||
}
|
||||
|
||||
type WarpOptions struct {
|
||||
Mode string `json:"mode"`
|
||||
WarpAccount
|
||||
warp.WireguardConfig
|
||||
FakePackets string `json:"fake-packets"`
|
||||
FakePacketSize string `json:"fake-packet-size"`
|
||||
FakePacketDelay string `json:"fake-packet-delay"`
|
||||
CleanIP string `json:"clean-ip"`
|
||||
CleanPort uint16 `json:"clean-port"`
|
||||
EnableWarp bool `json:"enable"`
|
||||
Mode string `json:"mode"`
|
||||
WireguardConfig WarpWireguardConfig `json:"wireguard-config"`
|
||||
FakePackets string `json:"fake-packets"`
|
||||
FakePacketSize string `json:"fake-packet-size"`
|
||||
FakePacketDelay string `json:"fake-packet-delay"`
|
||||
CleanIP string `json:"clean-ip"`
|
||||
CleanPort uint16 `json:"clean-port"`
|
||||
Account WarpAccount
|
||||
}
|
||||
|
||||
func DefaultConfigOptions() *ConfigOptions {
|
||||
|
||||
@@ -1,24 +1,59 @@
|
||||
package config
|
||||
|
||||
import "encoding/json"
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/bepass-org/wireguard-go/warp"
|
||||
)
|
||||
|
||||
type WarpAccount struct {
|
||||
AccountID string `json:"account-id"`
|
||||
AccessToken string `json:"access-token"`
|
||||
}
|
||||
|
||||
func GenerateWarpAccount(licenseKey string, accountId string, accessToken string) (string, error) {
|
||||
data, _, _, err := GenerateWarpInfo(licenseKey, accountId, accessToken)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
warpAccount := WarpAccount{
|
||||
AccountID: data.AccountID,
|
||||
AccessToken: data.AccessToken,
|
||||
}
|
||||
accountJson, err := json.Marshal(warpAccount)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(accountJson), nil
|
||||
type WarpWireguardConfig struct {
|
||||
PrivateKey string `json:"private-key"`
|
||||
LocalAddressIPv4 string `json:"local-address-ipv4"`
|
||||
LocalAddressIPv6 string `json:"local-address-ipv6"`
|
||||
PeerPublicKey string `json:"peer-public-key"`
|
||||
}
|
||||
|
||||
func (wg WarpWireguardConfig) ToWireguardConfig() warp.WireguardConfig {
|
||||
return warp.WireguardConfig{
|
||||
PrivateKey: wg.PrivateKey,
|
||||
LocalAddressIPv4: wg.LocalAddressIPv4,
|
||||
LocalAddressIPv6: wg.LocalAddressIPv6,
|
||||
PeerPublicKey: wg.PeerPublicKey,
|
||||
}
|
||||
}
|
||||
|
||||
type WarpGenerationResponse struct {
|
||||
WarpAccount
|
||||
Log string `json:"log"`
|
||||
Config WarpWireguardConfig `json:"config"`
|
||||
}
|
||||
|
||||
func GenerateWarpAccount(licenseKey string, accountId string, accessToken string) (string, error) {
|
||||
account, log, wg, err := GenerateWarpInfo(licenseKey, accountId, accessToken)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
warpAccount := WarpAccount{
|
||||
AccountID: account.AccountID,
|
||||
AccessToken: account.AccessToken,
|
||||
}
|
||||
warpConfig := WarpWireguardConfig{
|
||||
PrivateKey: wg.PrivateKey,
|
||||
LocalAddressIPv4: wg.LocalAddressIPv4,
|
||||
LocalAddressIPv6: wg.LocalAddressIPv6,
|
||||
PeerPublicKey: wg.PeerPublicKey,
|
||||
}
|
||||
response := WarpGenerationResponse{warpAccount, log, warpConfig}
|
||||
|
||||
responseJson, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(responseJson), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user