Skip to content

Commit 0fce2f3

Browse files
committed
neater abstractions pending, but here is dnsproxy listener
1 parent 21ec40e commit 0fce2f3

2 files changed

Lines changed: 430 additions & 0 deletions

File tree

intra/dnsproxy/listener.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright (c) 2021 RethinkDNS and its authors.
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
package dnsproxy
8+
9+
import "fmt"
10+
11+
const (
12+
// Complete : Transaction completed successfully
13+
Complete = iota
14+
// SendFailed : Failed to send query
15+
SendFailed
16+
// ProxyError : Got an error from upstream
17+
ProxyError
18+
// BadQuery : Malformed input
19+
BadQuery
20+
// BadResponse : Response was invalid
21+
BadResponse
22+
// InternalError : This should never happen
23+
InternalError
24+
)
25+
26+
type queryError struct {
27+
status int
28+
err error
29+
}
30+
31+
func (e *queryError) Error() string {
32+
return e.err.Error()
33+
}
34+
35+
func (e *queryError) Unwrap() error {
36+
return e.err
37+
}
38+
39+
type proxyError struct {
40+
status int
41+
}
42+
43+
func (e *proxyError) Error() string {
44+
return fmt.Sprintf("proxy request fail: %d", e.status)
45+
}
46+
47+
// Summary is a summary of a DNS transaction, reported when it is complete.
48+
type Summary struct {
49+
Latency float64 // Response (or failure) latency in seconds
50+
Query []byte
51+
Response []byte
52+
Server string
53+
Status int
54+
ProxyStatus int // Zero unless Status is Complete or ProxyError
55+
Blocklists string // csv separated list of blocklists names, if any.
56+
}
57+
58+
// A Token is an opaque handle used to match responses to queries.
59+
type Token interface{}
60+
61+
// Listener receives Summaries.
62+
type Listener interface {
63+
OnDNSProxyQuery(ipport string) Token
64+
OnDNSProxyResponse(Token, *Summary)
65+
}

0 commit comments

Comments
 (0)