Skip to content

Commit

Permalink
MINOR: create server option handlers on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati committed Nov 26, 2024
1 parent d8f73ba commit 6dc3242
Showing 1 changed file with 124 additions and 118 deletions.
242 changes: 124 additions & 118 deletions config-parser/params/server-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,134 +157,140 @@ func (b *ServerOptionIDValue) String() string {
return fmt.Sprintf("%s(%s) %s", b.Name, b.ID, b.Value)
}

func getServerOptions() []ServerOption {
return []ServerOption{
&ServerOptionWord{Name: "agent-check"},
&ServerOptionWord{Name: "allow-0rtt"},
&ServerOptionWord{Name: "backup"},
&ServerOptionWord{Name: "check"},
&ServerOptionWord{Name: "check-send-proxy"},
&ServerOptionWord{Name: "check-ssl"},
&ServerOptionWord{Name: "check-via-socks4"},
&ServerOptionWord{Name: "disabled"},
&ServerOptionWord{Name: "enabled"},
&ServerOptionWord{Name: "force-sslv3"},
&ServerOptionWord{Name: "force-tlsv10"},
&ServerOptionWord{Name: "force-tlsv11"},
&ServerOptionWord{Name: "force-tlsv12"},
&ServerOptionWord{Name: "force-tlsv13"},
&ServerOptionWord{Name: "no-agent-check"},
&ServerOptionWord{Name: "no-backup"},
&ServerOptionWord{Name: "no-check"},
&ServerOptionWord{Name: "no-check-ssl"},
&ServerOptionWord{Name: "no-send-proxy"},
&ServerOptionWord{Name: "no-send-proxy-v2"},
&ServerOptionWord{Name: "no-send-proxy-v2-ssl"},
&ServerOptionWord{Name: "no-send-proxy-v2-ssl-cn"},
&ServerOptionWord{Name: "no-ssl"},
&ServerOptionWord{Name: "no-ssl-reuse"},
&ServerOptionWord{Name: "no-sslv3"},
&ServerOptionWord{Name: "no-tls-tickets"},
&ServerOptionWord{Name: "no-tlsv10"},
&ServerOptionWord{Name: "no-tlsv11"},
&ServerOptionWord{Name: "no-tlsv12"},
&ServerOptionWord{Name: "no-tlsv13"},
&ServerOptionWord{Name: "no-verifyhost"},
&ServerOptionWord{Name: "no-tfo"},
&ServerOptionWord{Name: "non-stick"},
&ServerOptionWord{Name: "send-proxy"},
&ServerOptionWord{Name: "send-proxy-v2"},
&ServerOptionWord{Name: "send-proxy-v2-ssl"},
&ServerOptionWord{Name: "send-proxy-v2-ssl-cn"},
&ServerOptionWord{Name: "ssl"},
&ServerOptionWord{Name: "ssl-reuse"},
&ServerOptionWord{Name: "stick"},
&ServerOptionWord{Name: "tfo"},
&ServerOptionWord{Name: "tls-tickets"},
&ServerOptionValue{Name: "addr"},
&ServerOptionValue{Name: "agent-send"},
&ServerOptionValue{Name: "agent-inter"},
&ServerOptionValue{Name: "agent-addr"},
&ServerOptionValue{Name: "agent-port"},
&ServerOptionValue{Name: "alpn"},
&ServerOptionValue{Name: "ca-file"},
&ServerOptionValue{Name: "check-alpn"},
&ServerOptionValue{Name: "check-proto"},
&ServerOptionValue{Name: "check-sni"},
&ServerOptionValue{Name: "ciphers"},
&ServerOptionValue{Name: "ciphersuites"},
&ServerOptionValue{Name: "client-sigalgs"},
&ServerOptionValue{Name: "cookie"},
&ServerOptionValue{Name: "crl-file"},
&ServerOptionValue{Name: "crt"},
&ServerOptionValue{Name: "curves"},
&ServerOptionValue{Name: "error-limit"},
&ServerOptionValue{Name: "fall"},
&ServerOptionValue{Name: "id"},
&ServerOptionValue{Name: "init-addr"},
&ServerOptionValue{Name: "inter"},
&ServerOptionValue{Name: "fastinter"},
&ServerOptionValue{Name: "downinter"},
&ServerOptionValue{Name: "log-proto"},
&ServerOptionValue{Name: "maxconn"},
&ServerOptionValue{Name: "maxqueue"},
&ServerOptionValue{Name: "max-reuse"},
&ServerOptionValue{Name: "minconn"},
&ServerOptionValue{Name: "namespace"},
&ServerOptionValue{Name: "npn"},
&ServerOptionValue{Name: "observe"},
&ServerOptionValue{Name: "on-error"},
&ServerOptionValue{Name: "on-marked-down"},
&ServerOptionValue{Name: "on-marked-up"},
&ServerOptionValue{Name: "pool-max-conn"},
&ServerOptionValue{Name: "pool-purge-delay"},
&ServerOptionValue{Name: "port"},
&ServerOptionValue{Name: "proto"},
&ServerOptionValue{Name: "redir"},
&ServerOptionValue{Name: "rise"},
&ServerOptionValue{Name: "resolve-opts"},
&ServerOptionValue{Name: "resolve-prefer"},
&ServerOptionValue{Name: "resolve-net"},
&ServerOptionValue{Name: "resolvers"},
&ServerOptionValue{Name: "proxy-v2-options"},
&ServerOptionValue{Name: "shard"},
&ServerOptionValue{Name: "sigalgs"},
&ServerOptionValue{Name: "slowstart"},
&ServerOptionValue{Name: "sni"},
&ServerOptionValue{Name: "source"},
&ServerOptionValue{Name: "usesrc"},
&ServerOptionValue{Name: "interface"},
&ServerOptionValue{Name: "ssl-max-ver"},
&ServerOptionValue{Name: "ssl-min-ver"},
&ServerOptionValue{Name: "socks4"},
&ServerOptionValue{Name: "tcp-ut"},
&ServerOptionValue{Name: "track"},
&ServerOptionValue{Name: "verify"},
&ServerOptionValue{Name: "verifyhost"},
&ServerOptionValue{Name: "weight"},
&ServerOptionValue{Name: "pool-low-conn"},
&ServerOptionValue{Name: "ws"},
&ServerOptionValue{Name: "log-bufsize"},
&ServerOptionIDValue{Name: "set-proxy-v2-tlv-fmt"},
var serverOptionFactoryMethods = map[string]func() ServerOption{ //nolint:gochecknoglobals
"agent-check": func() ServerOption { return &ServerOptionWord{Name: "agent-check"} },
"allow-0rtt": func() ServerOption { return &ServerOptionWord{Name: "allow-0rtt"} },
"backup": func() ServerOption { return &ServerOptionWord{Name: "backup"} },
"check": func() ServerOption { return &ServerOptionWord{Name: "check"} },
"check-send-proxy": func() ServerOption { return &ServerOptionWord{Name: "check-send-proxy"} },
"check-ssl": func() ServerOption { return &ServerOptionWord{Name: "check-ssl"} },
"check-via-socks4": func() ServerOption { return &ServerOptionWord{Name: "check-via-socks4"} },
"disabled": func() ServerOption { return &ServerOptionWord{Name: "disabled"} },
"enabled": func() ServerOption { return &ServerOptionWord{Name: "enabled"} },
"force-sslv3": func() ServerOption { return &ServerOptionWord{Name: "force-sslv3"} },
"force-tlsv10": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv10"} },
"force-tlsv11": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv11"} },
"force-tlsv12": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv12"} },
"force-tlsv13": func() ServerOption { return &ServerOptionWord{Name: "force-tlsv13"} },
"no-agent-check": func() ServerOption { return &ServerOptionWord{Name: "no-agent-check"} },
"no-backup": func() ServerOption { return &ServerOptionWord{Name: "no-backup"} },
"no-check": func() ServerOption { return &ServerOptionWord{Name: "no-check"} },
"no-check-ssl": func() ServerOption { return &ServerOptionWord{Name: "no-check-ssl"} },
"no-send-proxy": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy"} },
"no-send-proxy-v2": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy-v2"} },
"no-send-proxy-v2-ssl": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy-v2-ssl"} },
"no-send-proxy-v2-ssl-cn": func() ServerOption { return &ServerOptionWord{Name: "no-send-proxy-v2-ssl-cn"} },
"no-ssl": func() ServerOption { return &ServerOptionWord{Name: "no-ssl"} },
"no-ssl-reuse": func() ServerOption { return &ServerOptionWord{Name: "no-ssl-reuse"} },
"no-sslv3": func() ServerOption { return &ServerOptionWord{Name: "no-sslv3"} },
"no-tls-tickets": func() ServerOption { return &ServerOptionWord{Name: "no-tls-tickets"} },
"no-tlsv10": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv10"} },
"no-tlsv11": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv11"} },
"no-tlsv12": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv12"} },
"no-tlsv13": func() ServerOption { return &ServerOptionWord{Name: "no-tlsv13"} },
"no-verifyhost": func() ServerOption { return &ServerOptionWord{Name: "no-verifyhost"} },
"no-tfo": func() ServerOption { return &ServerOptionWord{Name: "no-tfo"} },
"non-stick": func() ServerOption { return &ServerOptionWord{Name: "non-stick"} },
"send-proxy": func() ServerOption { return &ServerOptionWord{Name: "send-proxy"} },
"send-proxy-v2": func() ServerOption { return &ServerOptionWord{Name: "send-proxy-v2"} },
"send-proxy-v2-ssl": func() ServerOption { return &ServerOptionWord{Name: "send-proxy-v2-ssl"} },
"send-proxy-v2-ssl-cn": func() ServerOption { return &ServerOptionWord{Name: "send-proxy-v2-ssl-cn"} },
"ssl": func() ServerOption { return &ServerOptionWord{Name: "ssl"} },
"ssl-reuse": func() ServerOption { return &ServerOptionWord{Name: "ssl-reuse"} },
"stick": func() ServerOption { return &ServerOptionWord{Name: "stick"} },
"tfo": func() ServerOption { return &ServerOptionWord{Name: "tfo"} },
"tls-tickets": func() ServerOption { return &ServerOptionWord{Name: "tls-tickets"} },
"addr": func() ServerOption { return &ServerOptionValue{Name: "addr"} },
"agent-send": func() ServerOption { return &ServerOptionValue{Name: "agent-send"} },
"agent-inter": func() ServerOption { return &ServerOptionValue{Name: "agent-inter"} },
"agent-addr": func() ServerOption { return &ServerOptionValue{Name: "agent-addr"} },
"agent-port": func() ServerOption { return &ServerOptionValue{Name: "agent-port"} },
"alpn": func() ServerOption { return &ServerOptionValue{Name: "alpn"} },
"ca-file": func() ServerOption { return &ServerOptionValue{Name: "ca-file"} },
"check-alpn": func() ServerOption { return &ServerOptionValue{Name: "check-alpn"} },
"check-proto": func() ServerOption { return &ServerOptionValue{Name: "check-proto"} },
"check-sni": func() ServerOption { return &ServerOptionValue{Name: "check-sni"} },
"ciphers": func() ServerOption { return &ServerOptionValue{Name: "ciphers"} },
"ciphersuites": func() ServerOption { return &ServerOptionValue{Name: "ciphersuites"} },
"client-sigalgs": func() ServerOption { return &ServerOptionValue{Name: "client-sigalgs"} },
"cookie": func() ServerOption { return &ServerOptionValue{Name: "cookie"} },
"crl-file": func() ServerOption { return &ServerOptionValue{Name: "crl-file"} },
"crt": func() ServerOption { return &ServerOptionValue{Name: "crt"} },
"curves": func() ServerOption { return &ServerOptionValue{Name: "curves"} },
"error-limit": func() ServerOption { return &ServerOptionValue{Name: "error-limit"} },
"fall": func() ServerOption { return &ServerOptionValue{Name: "fall"} },
"id": func() ServerOption { return &ServerOptionValue{Name: "id"} },
"init-addr": func() ServerOption { return &ServerOptionValue{Name: "init-addr"} },
"inter": func() ServerOption { return &ServerOptionValue{Name: "inter"} },
"fastinter": func() ServerOption { return &ServerOptionValue{Name: "fastinter"} },
"downinter": func() ServerOption { return &ServerOptionValue{Name: "downinter"} },
"log-proto": func() ServerOption { return &ServerOptionValue{Name: "log-proto"} },
"maxconn": func() ServerOption { return &ServerOptionValue{Name: "maxconn"} },
"maxqueue": func() ServerOption { return &ServerOptionValue{Name: "maxqueue"} },
"max-reuse": func() ServerOption { return &ServerOptionValue{Name: "max-reuse"} },
"minconn": func() ServerOption { return &ServerOptionValue{Name: "minconn"} },
"namespace": func() ServerOption { return &ServerOptionValue{Name: "namespace"} },
"npn": func() ServerOption { return &ServerOptionValue{Name: "npn"} },
"observe": func() ServerOption { return &ServerOptionValue{Name: "observe"} },
"on-error": func() ServerOption { return &ServerOptionValue{Name: "on-error"} },
"on-marked-down": func() ServerOption { return &ServerOptionValue{Name: "on-marked-down"} },
"on-marked-up": func() ServerOption { return &ServerOptionValue{Name: "on-marked-up"} },
"pool-max-conn": func() ServerOption { return &ServerOptionValue{Name: "pool-max-conn"} },
"pool-purge-delay": func() ServerOption { return &ServerOptionValue{Name: "pool-purge-delay"} },
"port": func() ServerOption { return &ServerOptionValue{Name: "port"} },
"proto": func() ServerOption { return &ServerOptionValue{Name: "proto"} },
"redir": func() ServerOption { return &ServerOptionValue{Name: "redir"} },
"rise": func() ServerOption { return &ServerOptionValue{Name: "rise"} },
"resolve-opts": func() ServerOption { return &ServerOptionValue{Name: "resolve-opts"} },
"resolve-prefer": func() ServerOption { return &ServerOptionValue{Name: "resolve-prefer"} },
"resolve-net": func() ServerOption { return &ServerOptionValue{Name: "resolve-net"} },
"resolvers": func() ServerOption { return &ServerOptionValue{Name: "resolvers"} },
"proxy-v2-options": func() ServerOption { return &ServerOptionValue{Name: "proxy-v2-options"} },
"shard": func() ServerOption { return &ServerOptionValue{Name: "shard"} },
"sigalgs": func() ServerOption { return &ServerOptionValue{Name: "sigalgs"} },
"slowstart": func() ServerOption { return &ServerOptionValue{Name: "slowstart"} },
"sni": func() ServerOption { return &ServerOptionValue{Name: "sni"} },
"source": func() ServerOption { return &ServerOptionValue{Name: "source"} },
"usesrc": func() ServerOption { return &ServerOptionValue{Name: "usesrc"} },
"interface": func() ServerOption { return &ServerOptionValue{Name: "interface"} },
"ssl-max-ver": func() ServerOption { return &ServerOptionValue{Name: "ssl-max-ver"} },
"ssl-min-ver": func() ServerOption { return &ServerOptionValue{Name: "ssl-min-ver"} },
"socks4": func() ServerOption { return &ServerOptionValue{Name: "socks4"} },
"tcp-ut": func() ServerOption { return &ServerOptionValue{Name: "tcp-ut"} },
"track": func() ServerOption { return &ServerOptionValue{Name: "track"} },
"verify": func() ServerOption { return &ServerOptionValue{Name: "verify"} },
"verifyhost": func() ServerOption { return &ServerOptionValue{Name: "verifyhost"} },
"weight": func() ServerOption { return &ServerOptionValue{Name: "weight"} },
"pool-low-conn": func() ServerOption { return &ServerOptionValue{Name: "pool-low-conn"} },
"ws": func() ServerOption { return &ServerOptionValue{Name: "ws"} },
"log-bufsize": func() ServerOption { return &ServerOptionValue{Name: "log-bufsize"} },
"set-proxy-v2-tlv-fmt": func() ServerOption { return &ServerOptionIDValue{Name: "set-proxy-v2-tlv-fmt"} },
}

func getServerOption(option string) ServerOption {
option = strings.Split(option, "(")[0]

if factoryMethod, found := serverOptionFactoryMethods[option]; found {
return factoryMethod()
}
return nil
}

// Parse ...
func ParseServerOptions(options []string) []ServerOption {
result := []ServerOption{}
currentIndex := 0
for currentIndex < len(options) {
found := false
for _, parser := range getServerOptions() {
if size, err := parser.Parse(options, currentIndex); err == nil {
result = append(result, parser)
found = true
currentIndex += size
}
}
if !found {
serverOption := getServerOption(options[currentIndex])
if serverOption == nil {
currentIndex++
continue
}
if size, err := serverOption.Parse(options, currentIndex); err == nil {
result = append(result, serverOption)
currentIndex += size
}

}
return result
}
Expand Down

0 comments on commit 6dc3242

Please sign in to comment.