Skip to content

Commit

Permalink
feat: update bootstrap_dns_android (#966)
Browse files Browse the repository at this point in the history
* update with non_specified network

* remove wrongs

* add alternative bootstrapDialer

* do test

* Update dns_bootstrap_android_test.go

* example of alternative dialer

* public method

* move const

* Update dns_bootstrap_android_test.go

* no duplicated

* Rename infra/conf/dns_bootstrap_android.go to transport/internet/system_dns_android.go

* Update system_dns_android.go

* Update and rename infra/conf/dns_bootstrap_android_test.go to transport/internet/system_dns_android_test.go

* no imports

* Update system_dns_android.go

* Update system_dns_android_test.go

* create systemDNS

* Create system_dns_android.go

* Update system_dialer.go

* call Resolver on systemDialer

* create system_dns_test.go

* resolver.LookupIP params

* param fix

* noneed TestSystemDNSResolver

* revert: no specified resolver

* Delete system_dns.go

* android only

* android only test

* typo
  • Loading branch information
rurirei authored May 4, 2021
1 parent c66a167 commit 2129c6e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 52 deletions.
24 changes: 0 additions & 24 deletions infra/conf/dns_bootstrap_android.go

This file was deleted.

28 changes: 0 additions & 28 deletions infra/conf/dns_bootstrap_test.go

This file was deleted.

26 changes: 26 additions & 0 deletions transport/internet/system_dns_android.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build android

package internet

import (
"context"
"net"
)

const SystemDNS = "8.8.8.8:53"

type DNSResolverFunc func() *net.Resolver

var NewDNSResolver DNSResolverFunc = func() *net.Resolver {
return &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, _ string) (net.Conn, error) {
var dialer net.Dialer
return dialer.DialContext(ctx, network, SystemDNS)
},
}
}

func init() {
net.DefaultResolver = NewDNSResolver()
}
15 changes: 15 additions & 0 deletions transport/internet/system_dns_android_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build android

package internet

import (
"context"
"testing"
)

func TestDNSResolver(t *testing.T) {
resolver := NewDNSResolver()
if ips, err := resolver.LookupIP(context.Background(), "ip", "www.google.com"); err != nil {
t.Errorf("failed to lookupIP, %v, %v", ips, err)
}
}

0 comments on commit 2129c6e

Please sign in to comment.