-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgonnect_client.go
More file actions
131 lines (116 loc) · 3.7 KB
/
Copy pathgonnect_client.go
File metadata and controls
131 lines (116 loc) · 3.7 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package socksgo
import (
"context"
"net"
"github.com/asciimoth/gonnect"
)
// Static type assertions
var (
_ gonnect.Network = &GonnectClient{}
_ gonnect.Resolver = &GonnectClient{}
)
// GonnectClient wraps a Client to implement gonnect.Resolver and
// gonnect.Network interfaces. Resolver methods return "not found"
// errors as DNS resolution through SOCKS requires TorLookup to be enabled.
// Network interface methods return empty results as SOCKS proxies don't
// expose local network interfaces.
type GonnectClient struct {
*Client
}
// LookupCNAME implements gonnect.Resolver.LookupCNAME.
// Returns a "not found" error as CNAME lookup is not supported.
func (gc *GonnectClient) LookupCNAME(
ctx context.Context,
host string,
) (string, error) {
return "", &net.DNSError{
Err: "not found",
Name: host,
IsNotFound: true,
}
}
// LookupPort implements gonnect.Resolver.LookupPort.
// Returns a "not found" error as port lookup is not supported.
func (gc *GonnectClient) LookupPort(
ctx context.Context,
network, service string,
) (int, error) {
return gonnect.LookupPortOffline(network, service)
}
// LookupNS implements gonnect.Resolver.LookupNS.
// Returns a "not found" error as NS lookup is not supported.
func (gc *GonnectClient) LookupNS(
ctx context.Context,
name string,
) ([]*net.NS, error) {
return nil, &net.DNSError{
Err: "not found",
Name: name,
IsNotFound: true,
}
}
// LookupMX implements gonnect.Resolver.LookupMX.
// Returns a "no such host" error as MX lookup is not supported.
func (gc *GonnectClient) LookupMX(
ctx context.Context,
name string,
) ([]*net.MX, error) {
return nil, &net.DNSError{
Err: "no such host",
Name: name,
IsNotFound: true,
}
}
// LookupSRV implements gonnect.Resolver.LookupSRV.
// Returns a "no such host" error as SRV lookup is not supported.
func (gc *GonnectClient) LookupSRV(
ctx context.Context,
service, proto, name string,
) (string, []*net.SRV, error) {
return "", nil, &net.DNSError{
Err: "no such host",
Name: "_svc._" + proto + "." + name,
IsNotFound: true,
}
}
// LookupTXT implements gonnect.Resolver.LookupTXT.
// Returns a "no such host" error as TXT lookup is not supported.
func (gc *GonnectClient) LookupTXT(
ctx context.Context,
name string,
) ([]string, error) {
return nil, &net.DNSError{
Err: "no such host",
Name: name,
IsNotFound: true,
}
}
// Interfaces implements gonnect.Network.Interfaces.
// Returns an empty slice as SOCKS proxies don't expose local interfaces.
func (gc *GonnectClient) Interfaces() ([]gonnect.NetworkInterface, error) {
return []gonnect.NetworkInterface{}, nil
}
// InterfaceAddrs implements gonnect.Network.InterfaceAddrs.
// Returns an empty slice as SOCKS proxies don't expose local addresses.
func (gc *GonnectClient) InterfaceAddrs() ([]net.Addr, error) {
return []net.Addr{}, nil
}
// InterfaceMulticastAddrs implements gonnect.Network.InterfaceMulticastAddrs.
// Returns an empty slice as SOCKS proxies don't expose local multicast addresses.
func (gc *GonnectClient) InterfaceMulticastAddrs() ([]net.Addr, error) {
return []net.Addr{}, nil
}
// InterfacesByIndex implements gonnect.Network.InterfacesByIndex.
// Returns an interface-not-found error as no interfaces are available.
func (gc *GonnectClient) InterfacesByIndex(
index int,
) ([]gonnect.NetworkInterface, error) {
return nil, &net.AddrError{Err: "interface not found", Addr: ""}
}
// InterfacesByName implements gonnect.Network.InterfacesByName.
// Returns an interface-not-found error as no interfaces are available.
func (gc *GonnectClient) InterfacesByName(
name string,
) ([]gonnect.NetworkInterface, error) {
return nil, &net.AddrError{Err: "interface not found", Addr: ""}
}