-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathserver.go
54 lines (43 loc) · 1.08 KB
/
server.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
package anyproxy
import (
"context"
"fmt"
"net"
"net/url"
_ "github.com/wzshiming/shadowsocks/init"
)
// BytesPool is an interface for getting and returning temporary
// bytes for use by io.CopyBuffer.
type BytesPool interface {
Get() []byte
Put([]byte)
}
var schemeMap = map[string]SchemeFunc{}
func Register(scheme string, fun SchemeFunc) {
schemeMap[scheme] = fun
}
type Config struct {
RawQueries []string
Users []*url.Userinfo
Dialer Dialer
ListenConfig ListenConfig
Logger Logger
BytesPool BytesPool
}
type SchemeFunc func(ctx context.Context, scheme string, address string, conf *Config) (ServeConn, []string, error)
type ServeConn interface {
ServeConn(conn net.Conn)
}
type proxyURLs interface {
ProxyURLs() []string
}
type proxyURL interface {
ProxyURL() string
}
func NewServeConn(ctx context.Context, scheme string, address string, conf *Config) (ServeConn, []string, error) {
sch, ok := schemeMap[scheme]
if !ok || sch == nil {
return nil, nil, fmt.Errorf("can't support scheme %q", scheme)
}
return sch(ctx, scheme, address, conf)
}