home: imp code

This commit is contained in:
Stanislav Chzhen 2025-03-25 19:53:12 +03:00
parent 20be72abd4
commit 381f7666b0

View file

@ -717,44 +717,39 @@ func (m *tlsManager) checkPortAvailability(
protoDoQ = "DNS-over-QUIC" protoDoQ = "DNS-over-QUIC"
) )
type protoPort struct { needBindingCheck := []struct {
network string network string
proto string proto string
port uint16 currPort uint16
} newPort uint16
}{{
needBindingCheck := []protoPort{}
if currConf.PortHTTPS != newConf.PortHTTPS {
needBindingCheck = append(needBindingCheck, protoPort{
network: networkTCP, network: networkTCP,
proto: protoHTTPS, proto: protoHTTPS,
port: newConf.PortHTTPS, currPort: currConf.PortHTTPS,
}) newPort: newConf.PortHTTPS,
} }, {
if currConf.PortDNSOverTLS != newConf.PortDNSOverTLS {
needBindingCheck = append(needBindingCheck, protoPort{
network: networkTCP, network: networkTCP,
proto: protoDoT, proto: protoDoT,
port: newConf.PortDNSOverTLS, currPort: currConf.PortDNSOverTLS,
}) newPort: newConf.PortDNSOverTLS,
} }, {
if currConf.PortDNSOverQUIC != newConf.PortDNSOverQUIC {
needBindingCheck = append(needBindingCheck, protoPort{
network: networkUDP, network: networkUDP,
proto: protoDoQ, proto: protoDoQ,
port: newConf.PortDNSOverQUIC, currPort: currConf.PortDNSOverQUIC,
}) newPort: newConf.PortDNSOverQUIC,
} }}
var errs []error var errs []error
for _, v := range needBindingCheck { for _, v := range needBindingCheck {
addrPort := netip.AddrPortFrom(addr, v.port) port := v.newPort
if v.currPort == port {
continue
}
addrPort := netip.AddrPortFrom(addr, port)
err = aghnet.CheckPort(v.network, addrPort) err = aghnet.CheckPort(v.network, addrPort)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("port %d for %s is not available", v.port, v.proto)) errs = append(errs, fmt.Errorf("port %d for %s is not available", port, v.proto))
} }
} }