Addr returns the first listen address for the specified proto or nil if the proxy does not listen to it. proto must be one of [Proto]: [ProtoTCP], [ProtoUDP], [ProtoTLS], [ProtoHTTPS], [ProtoQUIC], or [ProtoDNSCrypt].
(proto Proto)
| 522 | // proxy does not listen to it. proto must be one of [Proto]: [ProtoTCP], |
| 523 | // [ProtoUDP], [ProtoTLS], [ProtoHTTPS], [ProtoQUIC], or [ProtoDNSCrypt]. |
| 524 | func (p *Proxy) Addr(proto Proto) (addr net.Addr) { |
| 525 | p.RLock() |
| 526 | defer p.RUnlock() |
| 527 | |
| 528 | switch proto { |
| 529 | case ProtoTCP: |
| 530 | return firstAddr(p.tcpListen, net.Listener.Addr) |
| 531 | case ProtoTLS: |
| 532 | return firstAddr(p.tlsListen, net.Listener.Addr) |
| 533 | case ProtoHTTPS: |
| 534 | return firstAddr(p.httpsListen, net.Listener.Addr) |
| 535 | case ProtoUDP: |
| 536 | return firstAddr(p.udpListen, (*net.UDPConn).LocalAddr) |
| 537 | case ProtoQUIC: |
| 538 | return firstAddr(p.quicListen, (*quic.EarlyListener).Addr) |
| 539 | case ProtoDNSCrypt: |
| 540 | return firstAddr(p.dnsCryptServers, (*dnscrypt.Server).LocalAddr) |
| 541 | default: |
| 542 | panic("proto must be 'tcp', 'tls', 'https', 'quic', 'dnscrypt' or 'udp'") |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | // selectUpstreams returns the upstreams to use for the specified host. It |
| 547 | // firstly considers custom upstreams if those aren't empty and then the |