-
Notifications
You must be signed in to change notification settings - Fork 75
/
base.go
44 lines (34 loc) · 938 Bytes
/
base.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
package outbound
import (
"context"
"net"
"github.com/xxf098/lite-proxy/common"
C "github.com/xxf098/lite-proxy/constant"
)
type Base struct {
name string
addr string
udp bool
}
type BasicOption struct {
Interface string `proxy:"interface-name,omitempty" group:"interface-name,omitempty"`
RoutingMark int `proxy:"routing-mark,omitempty" group:"routing-mark,omitempty"`
}
type ContextDialer interface {
DialContext(ctx context.Context, m *C.Metadata) (c net.Conn, err error)
}
type Dialer interface {
ContextDialer
DialUDP(m *C.Metadata) (net.PacketConn, error)
}
type Creator func(link string) (Dialer, error)
var creators = make(map[string]Creator)
func RegisterDialerCreator(name string, c Creator) {
creators[name] = c
}
func GetDialerCreator(name string) (Creator, error) {
if c, ok := creators[name]; ok {
return c, nil
}
return nil, common.NewError("unknown context dialer name " + string(name))
}