Skip to content

Commit

Permalink
home: upd quic port
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Mar 21, 2022
1 parent b9790f6 commit 9a77fc3
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 35 deletions.
34 changes: 23 additions & 11 deletions internal/home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,18 +292,18 @@ func parseConfig() (err error) {
uc := aghalg.UniqChecker{}
addPorts(
uc,
config.BindPort,
config.BetaBindPort,
config.DNS.Port,
tcpPort(config.BindPort),
tcpPort(config.BetaBindPort),
udpPort(config.DNS.Port),
)

if config.TLS.Enabled {
addPorts(
uc,
config.TLS.PortHTTPS,
config.TLS.PortDNSOverTLS,
config.TLS.PortDNSOverQUIC,
config.TLS.PortDNSCrypt,
tcpPort(config.TLS.PortHTTPS),
tcpPort(config.TLS.PortDNSOverTLS),
udpPort(config.TLS.PortDNSOverQUIC),
tcpPort(config.TLS.PortDNSCrypt),
)
}
if err = uc.Validate(aghalg.IntIsBefore); err != nil {
Expand All @@ -321,11 +321,23 @@ func parseConfig() (err error) {
return nil
}

// addPorts is a helper for ports validation. It skips zero ports.
func addPorts(uc aghalg.UniqChecker, ports ...int) {
// udpPort is the port number for UDP protocol.
type udpPort int

// tcpPort is the port number for TCP protocol.
type tcpPort int

// addPorts is a helper for ports validation. It skips zero ports. Each of
// ports should be either a udpPort or a tcpPort.
func addPorts(uc aghalg.UniqChecker, ports ...interface{}) {
for _, p := range ports {
if p != 0 {
uc.Add(p)
switch p := p.(type) {
case tcpPort, udpPort:
if p != 0 {
uc.Add(p)
}
default:
// Go on.
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/home/controlinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (req *checkConfReq) validateWeb(uc aghalg.UniqChecker) (err error) {
defer func() { err = errors.Annotate(err, "validating ports: %w") }()

port := req.Web.Port
addPorts(uc, config.BetaBindPort, port)
addPorts(uc, tcpPort(config.BetaBindPort), tcpPort(port))
if err = uc.Validate(aghalg.IntIsBefore); err != nil {
// Avoid duplicating the error into the status of DNS.
uc[port] = 1
Expand All @@ -135,7 +135,7 @@ func (req *checkConfReq) validateDNS(uc aghalg.UniqChecker) (canAutofix bool, er
defer func() { err = errors.Annotate(err, "validating ports: %w") }()

port := req.DNS.Port
addPorts(uc, port)
addPorts(uc, udpPort(port))
if err = uc.Validate(aghalg.IntIsBefore); err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/home/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
defaultPortDNS = 53
defaultPortHTTP = 80
defaultPortHTTPS = 443
defaultPortQUIC = 784
defaultPortQUIC = 853
defaultPortTLS = 853
)

Expand Down
14 changes: 7 additions & 7 deletions internal/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,17 @@ func setupConfig(args options) (err error) {
uc := aghalg.UniqChecker{}
addPorts(
uc,
args.bindPort,
config.BetaBindPort,
config.DNS.Port,
tcpPort(args.bindPort),
tcpPort(config.BetaBindPort),
udpPort(config.DNS.Port),
)
if config.TLS.Enabled {
addPorts(
uc,
config.TLS.PortHTTPS,
config.TLS.PortDNSOverTLS,
config.TLS.PortDNSOverQUIC,
config.TLS.PortDNSCrypt,
tcpPort(config.TLS.PortHTTPS),
tcpPort(config.TLS.PortDNSOverTLS),
udpPort(config.TLS.PortDNSOverQUIC),
tcpPort(config.TLS.PortDNSCrypt),
)
}
if err = uc.Validate(aghalg.IntIsBefore); err != nil {
Expand Down
28 changes: 14 additions & 14 deletions internal/home/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ func (t *TLSMod) handleTLSValidate(w http.ResponseWriter, r *http.Request) {
uc := aghalg.UniqChecker{}
addPorts(
uc,
config.BindPort,
config.BetaBindPort,
config.DNS.Port,
setts.PortHTTPS,
setts.PortDNSOverTLS,
setts.PortDNSOverQUIC,
setts.PortDNSCrypt,
tcpPort(config.BindPort),
tcpPort(config.BetaBindPort),
udpPort(config.DNS.Port),
tcpPort(setts.PortHTTPS),
tcpPort(setts.PortDNSOverTLS),
udpPort(setts.PortDNSOverQUIC),
tcpPort(setts.PortDNSCrypt),
)

err = uc.Validate(aghalg.IntIsBefore)
Expand Down Expand Up @@ -346,13 +346,13 @@ func (t *TLSMod) handleTLSConfigure(w http.ResponseWriter, r *http.Request) {
uc := aghalg.UniqChecker{}
addPorts(
uc,
config.BindPort,
config.BetaBindPort,
config.DNS.Port,
data.PortHTTPS,
data.PortDNSOverTLS,
data.PortDNSOverQUIC,
data.PortDNSCrypt,
tcpPort(config.BindPort),
tcpPort(config.BetaBindPort),
udpPort(config.DNS.Port),
tcpPort(data.PortHTTPS),
tcpPort(data.PortDNSOverTLS),
udpPort(data.PortDNSOverQUIC),
tcpPort(data.PortDNSCrypt),
)

err = uc.Validate(aghalg.IntIsBefore)
Expand Down

0 comments on commit 9a77fc3

Please sign in to comment.