Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
fix #96, 默认dns若连不上,会出现空指针闪退
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed May 15, 2022
1 parent 1c5cb23 commit a219ccb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion examples/multi.client.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ admin_pass = "adfadfadfadfa" # 用于 api服务器的登陆密码.只要给出,
# 只要dns模块存在并给出了servers,则所有域名请求都会被先解析成ip
# dns解析仅仅是为了能够精准分流, 如果你不需要分流, 没有自定义dns需求,则不需要dns模块

# dns解析的默认方式是先查A记录,没有A再查AAAA记录
# dns解析的默认方式是先查A记录,没有A再查AAAA记录 (先查4后查6)

#strategy = 60 # 0表示默认, 4表示先查ip4后查ip6, 6表示先查6后查4; 40表示只查ipv4, 60 表示只查ipv6
# 在只查 ipv6时, 有可能查无结果, 此时将依然会把域名原封不动发送到节点, 而不是断开连接.

# servers 列表中的 第一项 将被作为 默认 dns 服务器, 必须保证能连上,所以建议填写确实能连上的dns服务器,否则可能出问题

servers = [
"udp://114.114.114.114:53", # 如果把该url指向我们dokodemo监听的端口,就可以达到通过节点请求dns的目的.
#"udp://127.0.0.1:63782", # 如这一行 就是通过我们节点请求dns
Expand Down
3 changes: 2 additions & 1 deletion netLayer/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (dm *DNSMachine) AddNewServer(name string, addr *Addr) error {
dm.defaultConn = DnsConn{Conn: new(dns.Conn), raddr: addr, Name: name}
err := dm.defaultConn.Dial()
if err != nil {
dm.defaultConn.Conn = nil
return err
}
} else {
Expand Down Expand Up @@ -362,7 +363,7 @@ func (dm *DNSMachine) QueryType(domain string, dns_type uint16) (ip net.IP) {
}
}

if theDNSServerConn.Conn == nil { //如果配置文件只配置了自定义映射, 而没配置dns服务器的话, 那么我们就无法进行实际的dns查询
if theDNSServerConn.Conn == nil { //如果配置文件只配置了自定义映射, 而没配置dns服务器的话, 那么我们就无法进行实际的dns查询; 或者配置了,但是因为Dial失败,导致没有 实际的Conn
if ce := utils.CanLogDebug("[DNSMachine] no server configured, return nil."); ce != nil {
ce.Write()
}
Expand Down
10 changes: 8 additions & 2 deletions netLayer/dns_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ func LoadDnsMachine(conf *DnsConf) *DNSMachine {
continue
}

dm.AddNewServer(server, &ad)
if err := dm.AddNewServer(server, &ad); err != nil {
if ce := utils.CanLogErr("LoadDnsMachine, AddNewServer by string failed"); ce != nil {
ce.Write(zap.Error(err))
}

continue
}

case map[string]any:

Expand Down Expand Up @@ -121,7 +127,7 @@ func LoadDnsMachine(conf *DnsConf) *DNSMachine {

if err := dm.AddNewServer(realServer.AddrUrlStr, &addr); err != nil {

if ce := utils.CanLogErr("LoadDnsMachine, AddNewServer failed"); ce != nil {
if ce := utils.CanLogErr("LoadDnsMachine, AddNewServer by map failed"); ce != nil {
ce.Write(zap.Error(err))
}

Expand Down

0 comments on commit a219ccb

Please sign in to comment.