Skip to content

Commit 89fc43b

Browse files
committed
Rename functions
1 parent e54c45a commit 89fc43b

10 files changed

Lines changed: 73 additions & 73 deletions

‎dnscrypt-proxy/config.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
382382
proxy.userName = config.UserName
383383
proxy.child = *flags.Child
384384
proxy.enableHotReload = config.EnableHotReload
385-
proxy.outboundSource, err = parseOutboundSourcePolicy(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
385+
proxy.outboundSource, err = parseOutboundSources(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
386386
if err != nil {
387387
return err
388388
}
@@ -398,7 +398,7 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
398398
if err := configureXTransport(proxy, &config); err != nil {
399399
return err
400400
}
401-
logOutboundSourcePolicy(&proxy.outboundSource, proxy.xTransport.ignoreSystemDNS)
401+
logOutboundSources(&proxy.outboundSource, proxy.xTransport.ignoreSystemDNS)
402402

403403
// Configure DoH client authentication
404404
if err := configureDoHClientAuth(proxy, &config); err != nil {

‎dnscrypt-proxy/config_loader.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func configureLogging(proxy *Proxy, flags *ConfigFlags, config *Config) {
7171
}
7272
}
7373

74-
// logOutboundSourcePolicy reports missing source families and effective system DNS exclusions.
75-
func logOutboundSourcePolicy(policy *outboundSourcePolicy, ignoreSystemDNS bool) {
74+
// logOutboundSources reports missing source families and effective system DNS exclusions.
75+
func logOutboundSources(policy *outboundSourcePolicy, ignoreSystemDNS bool) {
7676
if !policy.enabled() {
7777
return
7878
}
@@ -141,7 +141,7 @@ func configureXTransport(proxy *Proxy, config *Config) error {
141141
}
142142
forwardDialer := netproxy.Dialer(netproxy.Direct)
143143
if proxy.outboundSource.enabled() {
144-
forwardDialer = &sourceAwareProxyForwardDialer{xTransport: proxy.xTransport}
144+
forwardDialer = &proxyDialer{xTransport: proxy.xTransport}
145145
}
146146
proxyDialer, err := netproxy.FromURL(proxyDialerURL, forwardDialer)
147147
if err != nil {

‎dnscrypt-proxy/config_outbound_source_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/BurntSushi/toml"
88
)
99

10-
func TestOutboundSourceConfigTOML(t *testing.T) {
10+
func TestOutboundSourceConfig(t *testing.T) {
1111
tests := []struct {
1212
name string
1313
toml string
@@ -40,7 +40,7 @@ func TestOutboundSourceConfigTOML(t *testing.T) {
4040
if _, err := toml.Decode(test.toml, &config); err != nil {
4141
t.Fatal(err)
4242
}
43-
policy, err := parseOutboundSourcePolicy(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
43+
policy, err := parseOutboundSources(config.OutboundSourceIPv4, config.OutboundSourceIPv6)
4444
if test.wantError != "" {
4545
if err == nil || !strings.Contains(err.Error(), test.wantError) {
4646
t.Fatalf("error = %v, want containing %q", err, test.wantError)

‎dnscrypt-proxy/dnsutils_outbound_source_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
)
1010

1111
func TestDNSExchangeOutboundSource(t *testing.T) {
12-
sourceIP := usableNonLoopbackIPv4(t)
13-
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
12+
sourceIP := nonLoopbackIPv4(t)
13+
policy, err := parseOutboundSources(sourceIP.String(), "")
1414
if err != nil {
1515
t.Fatal(err)
1616
}
@@ -24,7 +24,7 @@ func TestDNSExchangeOutboundSource(t *testing.T) {
2424
name = proto + "-relayed"
2525
}
2626
t.Run(name, func(t *testing.T) {
27-
relayAddress, peerCh, closeServer := startOutboundDNSServer(t, proto, sourceIP, relayed, nil)
27+
relayAddress, peerCh, closeServer := startTestDNS(t, proto, sourceIP, relayed, nil)
2828
serverAddress := relayAddress.String()
2929
if relayed {
3030
serverAddress = "9.9.9.9:53"
@@ -53,7 +53,7 @@ func TestDNSExchangeOutboundSource(t *testing.T) {
5353
}
5454
}
5555

56-
func startOutboundDNSServer(t *testing.T, proto string, destinationIP net.IP, relayed bool, answer func(*dns.Msg)) (net.Addr, <-chan net.IP, func()) {
56+
func startTestDNS(t *testing.T, proto string, destinationIP net.IP, relayed bool, answer func(*dns.Msg)) (net.Addr, <-chan net.IP, func()) {
5757
t.Helper()
5858
peerCh := make(chan net.IP, 1)
5959
respond := func(packet []byte) []byte {

‎dnscrypt-proxy/outbound_source.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type outboundTarget struct {
2121
source netip.Addr
2222
}
2323

24-
func parseOutboundSourcePolicy(ipv4Str, ipv6Str string) (outboundSourcePolicy, error) {
24+
func parseOutboundSources(ipv4Str, ipv6Str string) (outboundSourcePolicy, error) {
2525
var policy outboundSourcePolicy
2626
for _, field := range []struct {
2727
family int

‎dnscrypt-proxy/outbound_source_test.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
func usableNonLoopbackIPv4(t *testing.T) net.IP {
11+
func nonLoopbackIPv4(t *testing.T) net.IP {
1212
t.Helper()
1313
addrs, err := net.InterfaceAddrs()
1414
if err != nil {
@@ -24,8 +24,8 @@ func usableNonLoopbackIPv4(t *testing.T) net.IP {
2424
return nil
2525
}
2626

27-
func TestOutboundSourceUDPListenerLocalBypass(t *testing.T) {
28-
policy, err := parseOutboundSourcePolicy("192.0.2.10", "2001:db8::10")
27+
func TestListenUDPLoopback(t *testing.T) {
28+
policy, err := parseOutboundSources("192.0.2.10", "2001:db8::10")
2929
if err != nil {
3030
t.Fatal(err)
3131
}
@@ -41,7 +41,7 @@ func TestOutboundSourceUDPListenerLocalBypass(t *testing.T) {
4141
}
4242

4343
func TestOutboundSourceFor(t *testing.T) {
44-
policy, err := parseOutboundSourcePolicy("192.0.2.10", "2001:db8::10")
44+
policy, err := parseOutboundSources("192.0.2.10", "2001:db8::10")
4545
if err != nil {
4646
t.Fatal(err)
4747
}
@@ -83,8 +83,8 @@ func TestOutboundSourceFor(t *testing.T) {
8383
}
8484
}
8585

86-
func TestOutboundSourceDialerOptionsAndZones(t *testing.T) {
87-
policy, err := parseOutboundSourcePolicy("192.0.2.10", "fe80::1%en0")
86+
func TestSourceDialerOptions(t *testing.T) {
87+
policy, err := parseOutboundSources("192.0.2.10", "fe80::1%en0")
8888
if err != nil {
8989
t.Fatal(err)
9090
}
@@ -105,7 +105,7 @@ func TestOutboundSourceDialerOptionsAndZones(t *testing.T) {
105105
}
106106
}
107107

108-
func TestNewDNSTransportHasIndependentDialer(t *testing.T) {
108+
func TestDNSTransportDialerIsolation(t *testing.T) {
109109
first := newDNSTransport()
110110
second := newDNSTransport()
111111
if first.Dialer.Timeout != 5*time.Second || first.Dialer.KeepAlive != 3*time.Second {
@@ -117,8 +117,8 @@ func TestNewDNSTransportHasIndependentDialer(t *testing.T) {
117117
}
118118
}
119119

120-
func TestConfigureOutboundDialer(t *testing.T) {
121-
policy, err := parseOutboundSourcePolicy("192.0.2.10", "2001:db8::10")
120+
func TestSourceDialer(t *testing.T) {
121+
policy, err := parseOutboundSources("192.0.2.10", "2001:db8::10")
122122
if err != nil {
123123
t.Fatal(err)
124124
}
@@ -136,8 +136,8 @@ func TestConfigureOutboundDialer(t *testing.T) {
136136
}
137137
}
138138

139-
func TestOutboundSourceDNSErrorContext(t *testing.T) {
140-
policy, err := parseOutboundSourcePolicy("192.0.2.10", "")
139+
func TestSourceDNSError(t *testing.T) {
140+
policy, err := parseOutboundSources("192.0.2.10", "")
141141
if err != nil {
142142
t.Fatal(err)
143143
}

‎dnscrypt-proxy/plugin_dns64_outbound_source_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"codeberg.org/miekg/dns/rdata"
1010
)
1111

12-
func TestDNS64DiscoveryOutboundSource(t *testing.T) {
13-
sourceIP := usableNonLoopbackIPv4(t)
14-
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
12+
func TestDNS64SourceBinding(t *testing.T) {
13+
sourceIP := nonLoopbackIPv4(t)
14+
policy, err := parseOutboundSources(sourceIP.String(), "")
1515
if err != nil {
1616
t.Fatal(err)
1717
}
18-
resolver, peerCh, closeServer := startOutboundDNSServer(t, "udp", sourceIP, false, func(msg *dns.Msg) {
18+
resolver, peerCh, closeServer := startTestDNS(t, "udp", sourceIP, false, func(msg *dns.Msg) {
1919
msg.Answer = []dns.RR{&dns.AAAA{
2020
Hdr: dns.Header{Name: rfc7050WKN, Class: dns.ClassINET, TTL: 60},
2121
AAAA: rdata.AAAA{Addr: netip.MustParseAddr("64:ff9b::c000:aa")},

‎dnscrypt-proxy/udp_conn_pool_test.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
"time"
1010
)
1111

12-
func TestUDPConnPool_OutboundSource(t *testing.T) {
13-
sourceIP := usableNonLoopbackIPv4(t)
14-
policy, err := parseOutboundSourcePolicy(sourceIP.String(), "")
12+
func TestUDPConnPool_SourceBinding(t *testing.T) {
13+
sourceIP := nonLoopbackIPv4(t)
14+
policy, err := parseOutboundSources(sourceIP.String(), "")
1515
if err != nil {
1616
t.Fatal(err)
1717
}
@@ -64,8 +64,8 @@ func TestUDPConnPool_OutboundSource(t *testing.T) {
6464
pool.Discard(replacement)
6565
}
6666

67-
func TestUDPConnPool_OutboundSourceLoopbackBypass(t *testing.T) {
68-
policy, err := parseOutboundSourcePolicy("192.0.2.1", "")
67+
func TestUDPConnPool_Loopback(t *testing.T) {
68+
policy, err := parseOutboundSources("192.0.2.1", "")
6969
if err != nil {
7070
t.Fatal(err)
7171
}
@@ -86,13 +86,13 @@ func TestUDPConnPool_OutboundSourceLoopbackBypass(t *testing.T) {
8686
}
8787
}
8888

89-
func TestUDPConnPool_OutboundSourceBindFailure(t *testing.T) {
90-
destinationIP := usableNonLoopbackIPv4(t)
89+
func TestUDPConnPool_BindFailure(t *testing.T) {
90+
destinationIP := nonLoopbackIPv4(t)
9191
configured := "192.0.2.1"
9292
if destinationIP.Equal(net.ParseIP(configured)) {
9393
configured = "198.51.100.1"
9494
}
95-
policy, err := parseOutboundSourcePolicy(configured, "")
95+
policy, err := parseOutboundSources(configured, "")
9696
if err != nil {
9797
t.Fatal(err)
9898
}

‎dnscrypt-proxy/xtransport.go‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,18 @@ type XTransport struct {
106106
outboundSource *outboundSourcePolicy
107107
}
108108

109-
type sourceAwareProxyForwardDialer struct {
109+
type proxyDialer struct {
110110
xTransport *XTransport
111111
}
112112

113-
var _ netproxy.Dialer = (*sourceAwareProxyForwardDialer)(nil)
114-
var _ netproxy.ContextDialer = (*sourceAwareProxyForwardDialer)(nil)
113+
var _ netproxy.Dialer = (*proxyDialer)(nil)
114+
var _ netproxy.ContextDialer = (*proxyDialer)(nil)
115115

116-
func (dialer *sourceAwareProxyForwardDialer) Dial(network, address string) (net.Conn, error) {
116+
func (dialer *proxyDialer) Dial(network, address string) (net.Conn, error) {
117117
return dialer.DialContext(context.Background(), network, address)
118118
}
119119

120-
func (dialer *sourceAwareProxyForwardDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
120+
func (dialer *proxyDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
121121
if network != "tcp" && network != "tcp4" && network != "tcp6" {
122122
return nil, fmt.Errorf("unsupported proxy forward network %q", network)
123123
}
@@ -133,7 +133,7 @@ func (dialer *sourceAwareProxyForwardDialer) DialContext(ctx context.Context, ne
133133
if literal, err := netip.ParseAddr(host); err == nil {
134134
addresses = []netip.Addr{literal}
135135
} else {
136-
ips, _, err := dialer.xTransport.resolveProxyEndpoint(host)
136+
ips, _, err := dialer.xTransport.resolveProxy(host)
137137
if err != nil {
138138
return nil, fmt.Errorf("unable to resolve proxy endpoint %q: %w", host, err)
139139
}
@@ -373,7 +373,7 @@ func (xTransport *XTransport) rebuildTransport() {
373373

374374
cachedIPs, _, _ := xTransport.loadCachedIPs(host)
375375
if xTransport.outboundSource.enabled() && xTransport.proxyDialer == nil && len(cachedIPs) == 0 {
376-
resolved, err := xTransport.coveredDestinationIPs(host, "HTTP")
376+
resolved, err := xTransport.resolveDialIPs(host, "HTTP")
377377
if err != nil {
378378
return nil, err
379379
}
@@ -538,7 +538,7 @@ func (xTransport *XTransport) rebuildTransport() {
538538

539539
cachedIPs, _, _ := xTransport.loadCachedIPs(host)
540540
if xTransport.outboundSource.enabled() && len(cachedIPs) == 0 {
541-
resolved, err := xTransport.coveredDestinationIPs(host, "HTTP/3")
541+
resolved, err := xTransport.resolveDialIPs(host, "HTTP/3")
542542
if err != nil {
543543
return nil, err
544544
}
@@ -599,16 +599,16 @@ func (xTransport *XTransport) rebuildTransport() {
599599
}
600600
}
601601

602-
// coveredDestinationIPs resolves through the configured DNS policy before source binding.
603-
func (xTransport *XTransport) coveredDestinationIPs(host, kind string) ([]net.IP, error) {
602+
// resolveDialIPs resolves through the configured DNS policy before source binding.
603+
func (xTransport *XTransport) resolveDialIPs(host, kind string) ([]net.IP, error) {
604604
if literal := ParseIP(host); literal != nil {
605605
return []net.IP{literal}, nil
606606
}
607607
var ips []net.IP
608608
var ttl time.Duration
609609
var err error
610610
if xTransport.httpProxyFunction != nil && kind == "HTTP" {
611-
ips, ttl, err = xTransport.resolveProxyEndpoint(host)
611+
ips, ttl, err = xTransport.resolveProxy(host)
612612
} else {
613613
ips, ttl, err = xTransport.resolve(host, xTransport.useIPv4, xTransport.useIPv6)
614614
}
@@ -752,8 +752,8 @@ func (xTransport *XTransport) resolve(host string, returnIPv4, returnIPv6 bool)
752752
return xTransport.resolveHost(host, returnIPv4, returnIPv6, true)
753753
}
754754

755-
// resolveProxyEndpoint avoids depending on the proxy to resolve its own address.
756-
func (xTransport *XTransport) resolveProxyEndpoint(host string) ([]net.IP, time.Duration, error) {
755+
// resolveProxy avoids depending on the proxy to resolve its own address.
756+
func (xTransport *XTransport) resolveProxy(host string) ([]net.IP, time.Duration, error) {
757757
return xTransport.resolveHost(host, xTransport.useIPv4, xTransport.useIPv6, false)
758758
}
759759

0 commit comments

Comments
 (0)