Skip to content

Commit

Permalink
Merge pull request #84 from telekom-mms/feature/update-dnsproxy
Browse files Browse the repository at this point in the history
Feature/update dnsproxy
  • Loading branch information
hwipl committed May 13, 2024
2 parents cef4fde + 5243520 commit 0bc82d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/dnsproxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ type Proxy struct {
closed chan struct{}
}

// sendReport sends report over the reports channel.
func (p *Proxy) sendReport(report *Report) {
select {
case p.reports <- report:
case <-p.done:
}
}

// handleRequest handles a dns client request.
func (p *Proxy) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
// make sure the client request is valid
Expand Down Expand Up @@ -86,7 +94,7 @@ func (p *Proxy) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
return
}
report := NewReport(rr.Hdr.Name, rr.A, rr.Hdr.Ttl)
p.reports <- report
p.sendReport(report)
report.Wait()
}

Expand All @@ -99,7 +107,7 @@ func (p *Proxy) handleRequest(w dns.ResponseWriter, r *dns.Msg) {
return
}
report := NewReport(rr.Hdr.Name, rr.AAAA, rr.Hdr.Ttl)
p.reports <- report
p.sendReport(report)
report.Wait()
}

Expand Down
4 changes: 4 additions & 0 deletions internal/dnsproxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ func TestProxyHandleRequest(t *testing.T) {

// with watches in proxy
p.SetWatches([]string{"test.example.com."})
reportsDone := make(chan struct{})
go func() {
defer close(reportsDone)
for r := range p.Reports() {
r.Done()
}
}()
p.handleRequest(&responseWriter{}, &dns.Msg{Question: []dns.Question{{Name: "test.example.com."}}})
close(p.reports)
<-reportsDone
}

// TestProxyHandleRequest tests handleRequest of Proxy, DNS records.
Expand Down

0 comments on commit 0bc82d1

Please sign in to comment.