mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 00:04:02 +03:00
Add new option for preferring of new IP
This commit is contained in:
@@ -32,6 +32,13 @@ const (
|
|||||||
SecretModeTLS
|
SecretModeTLS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PreferIP uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
PreferIPv4 PreferIP = iota
|
||||||
|
PreferIPv6
|
||||||
|
)
|
||||||
|
|
||||||
const SimpleSecretLength = 16
|
const SimpleSecretLength = 16
|
||||||
|
|
||||||
type OptionType uint8
|
type OptionType uint8
|
||||||
@@ -40,6 +47,8 @@ const (
|
|||||||
OptionTypeDebug OptionType = iota
|
OptionTypeDebug OptionType = iota
|
||||||
OptionTypeVerbose
|
OptionTypeVerbose
|
||||||
|
|
||||||
|
OptionTypePreferIP
|
||||||
|
|
||||||
OptionTypeBind
|
OptionTypeBind
|
||||||
OptionTypePublicIPv4
|
OptionTypePublicIPv4
|
||||||
OptionTypePublicIPv6
|
OptionTypePublicIPv6
|
||||||
@@ -86,6 +95,7 @@ type Config struct {
|
|||||||
Debug bool `json:"debug"`
|
Debug bool `json:"debug"`
|
||||||
Verbose bool `json:"verbose"`
|
Verbose bool `json:"verbose"`
|
||||||
SecretMode SecretMode `json:"secret_mode"`
|
SecretMode SecretMode `json:"secret_mode"`
|
||||||
|
PreferIP PreferIP `json:"prefer_ip"`
|
||||||
|
|
||||||
Secret []byte `json:"secret"`
|
Secret []byte `json:"secret"`
|
||||||
AdTag []byte `json:"adtag"`
|
AdTag []byte `json:"adtag"`
|
||||||
@@ -105,6 +115,16 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen
|
|||||||
C.Debug = opt.Value.(bool)
|
C.Debug = opt.Value.(bool)
|
||||||
case OptionTypeVerbose:
|
case OptionTypeVerbose:
|
||||||
C.Verbose = opt.Value.(bool)
|
C.Verbose = opt.Value.(bool)
|
||||||
|
case OptionTypePreferIP:
|
||||||
|
value := opt.Value.(string)
|
||||||
|
switch value {
|
||||||
|
case "ipv4":
|
||||||
|
C.PreferIP = PreferIPv4
|
||||||
|
case "ipv6":
|
||||||
|
C.PreferIP = PreferIPv6
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("incorrect direct IP mode %s", value)
|
||||||
|
}
|
||||||
case OptionTypeBind:
|
case OptionTypeBind:
|
||||||
C.Bind = opt.Value.(*net.TCPAddr)
|
C.Bind = opt.Value.(*net.TCPAddr)
|
||||||
case OptionTypePublicIPv4:
|
case OptionTypePublicIPv4:
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ var (
|
|||||||
Short('v').
|
Short('v').
|
||||||
Envar("MTG_VERBOSE").
|
Envar("MTG_VERBOSE").
|
||||||
Bool()
|
Bool()
|
||||||
|
runPreferIP = runCommand.Flag("prefer-ip",
|
||||||
|
"Prefer this IP protocol if possible. Valid options are 'ipv4' and 'ipv6'").
|
||||||
|
Envar("MTG_PREFER_DIRECT_IP").
|
||||||
|
Default("ipv6").
|
||||||
|
Enum("ipv4", "ipv6")
|
||||||
runBind = runCommand.Flag("bind",
|
runBind = runCommand.Flag("bind",
|
||||||
"Host:Port to bind proxy to.").
|
"Host:Port to bind proxy to.").
|
||||||
Short('b').
|
Short('b').
|
||||||
@@ -130,6 +135,7 @@ func main() {
|
|||||||
err := config.Init(
|
err := config.Init(
|
||||||
config.Opt{Option: config.OptionTypeDebug, Value: *runDebug},
|
config.Opt{Option: config.OptionTypeDebug, Value: *runDebug},
|
||||||
config.Opt{Option: config.OptionTypeVerbose, Value: *runVerbose},
|
config.Opt{Option: config.OptionTypeVerbose, Value: *runVerbose},
|
||||||
|
config.Opt{Option: config.OptionTypePreferIP, Value: *runPreferIP},
|
||||||
config.Opt{Option: config.OptionTypeBind, Value: *runBind},
|
config.Opt{Option: config.OptionTypeBind, Value: *runBind},
|
||||||
config.Opt{Option: config.OptionTypePublicIPv4, Value: *runPublicIPv4},
|
config.Opt{Option: config.OptionTypePublicIPv4, Value: *runPublicIPv4},
|
||||||
config.Opt{Option: config.OptionTypePublicIPv6, Value: *runPublicIPv6},
|
config.Opt{Option: config.OptionTypePublicIPv6, Value: *runPublicIPv6},
|
||||||
|
|||||||
Reference in New Issue
Block a user