-
Notifications
You must be signed in to change notification settings - Fork 28
/
transport_rcode.go
78 lines (64 loc) · 1.71 KB
/
transport_rcode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package dns
import (
"context"
"net/netip"
"net/url"
"os"
E "github.com/sagernet/sing/common/exceptions"
"github.com/miekg/dns"
)
var _ Transport = (*RCodeTransport)(nil)
func init() {
RegisterTransport([]string{"rcode"}, func(options TransportOptions) (Transport, error) {
return NewRCodeTransport(options)
})
}
type RCodeTransport struct {
name string
code RCodeError
}
func NewRCodeTransport(options TransportOptions) (*RCodeTransport, error) {
serverURL, err := url.Parse(options.Address)
if err != nil {
return nil, err
}
switch serverURL.Host {
case "success":
return &RCodeTransport{options.Name, RCodeSuccess}, nil
case "format_error":
return &RCodeTransport{options.Name, RCodeFormatError}, nil
case "server_failure":
return &RCodeTransport{options.Name, RCodeServerFailure}, nil
case "name_error":
return &RCodeTransport{options.Name, RCodeNameError}, nil
case "not_implemented":
return &RCodeTransport{options.Name, RCodeNotImplemented}, nil
case "refused":
return &RCodeTransport{options.Name, RCodeRefused}, nil
default:
return nil, E.New("unknown rcode: " + options.Name)
}
}
func (t *RCodeTransport) Name() string {
return t.name
}
func (t *RCodeTransport) Start() error {
return nil
}
func (t *RCodeTransport) Reset() {
}
func (t *RCodeTransport) Close() error {
return nil
}
func (t *RCodeTransport) Raw() bool {
return true
}
func (t *RCodeTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error) {
exMessage := *message
exMessage.Response = true
exMessage.Rcode = int(t.code)
return &exMessage, nil
}
func (t *RCodeTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error) {
return nil, os.ErrInvalid
}