mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
report pack error instead of panic
This commit is contained in:
parent
755415056b
commit
e736c08794
@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"v2ray.com/core/app/dispatcher"
|
"v2ray.com/core/app/dispatcher"
|
||||||
"v2ray.com/core/common"
|
|
||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/dice"
|
"v2ray.com/core/common/dice"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
@ -143,7 +142,7 @@ func (s *UDPNameServer) HandleResponse(payload *buf.Buffer) {
|
|||||||
close(request.response)
|
close(request.response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UDPNameServer) BuildQueryA(domain string, id uint16) *buf.Buffer {
|
func (s *UDPNameServer) buildAMsg(domain string, id uint16) *dns.Msg {
|
||||||
msg := new(dns.Msg)
|
msg := new(dns.Msg)
|
||||||
msg.Id = id
|
msg.Id = id
|
||||||
msg.RecursionDesired = true
|
msg.RecursionDesired = true
|
||||||
@ -161,21 +160,34 @@ func (s *UDPNameServer) BuildQueryA(domain string, id uint16) *buf.Buffer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgToBuffer(msg *dns.Msg) (*buf.Buffer, error) {
|
||||||
buffer := buf.New()
|
buffer := buf.New()
|
||||||
common.Must(buffer.Reset(func(b []byte) (int, error) {
|
if err := buffer.Reset(func(b []byte) (int, error) {
|
||||||
writtenBuffer, err := msg.PackBuffer(b)
|
writtenBuffer, err := msg.PackBuffer(b)
|
||||||
return len(writtenBuffer), err
|
return len(writtenBuffer), err
|
||||||
}))
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
return buffer
|
}
|
||||||
|
return buffer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UDPNameServer) QueryA(domain string) <-chan *ARecord {
|
func (s *UDPNameServer) QueryA(domain string) <-chan *ARecord {
|
||||||
response := make(chan *ARecord, 1)
|
response := make(chan *ARecord, 1)
|
||||||
id := s.AssignUnusedID(response)
|
id := s.AssignUnusedID(response)
|
||||||
|
|
||||||
|
msg := s.buildAMsg(domain, id)
|
||||||
|
b, err := msgToBuffer(msg)
|
||||||
|
if err != nil {
|
||||||
|
newError("failed to build A query for domain ", domain).Base(err).WriteToLog()
|
||||||
|
close(response)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
s.udpServer.Dispatch(ctx, s.address, s.BuildQueryA(domain, id), s.HandleResponse)
|
s.udpServer.Dispatch(ctx, s.address, b, s.HandleResponse)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
@ -186,7 +198,8 @@ func (s *UDPNameServer) QueryA(domain string) <-chan *ARecord {
|
|||||||
if !found {
|
if !found {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
s.udpServer.Dispatch(ctx, s.address, s.BuildQueryA(domain, id), s.HandleResponse)
|
b, _ := msgToBuffer(msg)
|
||||||
|
s.udpServer.Dispatch(ctx, s.address, b, s.HandleResponse)
|
||||||
}
|
}
|
||||||
cancel()
|
cancel()
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user