forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxyman.go
69 lines (55 loc) · 1.52 KB
/
proxyman.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
package proxyman
import (
"sync"
"github.com/v2ray/v2ray-core/app"
"github.com/v2ray/v2ray-core/proxy"
)
const (
APP_ID_INBOUND_MANAGER = app.ID(4)
APP_ID_OUTBOUND_MANAGER = app.ID(6)
)
type InboundHandlerManager interface {
GetHandler(tag string) (proxy.InboundHandler, int)
}
type OutboundHandlerManager interface {
GetHandler(tag string) proxy.OutboundHandler
GetDefaultHandler() proxy.OutboundHandler
}
type DefaultOutboundHandlerManager struct {
sync.RWMutex
defaultHandler proxy.OutboundHandler
taggedHandler map[string]proxy.OutboundHandler
}
func NewDefaultOutboundHandlerManager() *DefaultOutboundHandlerManager {
return &DefaultOutboundHandlerManager{
taggedHandler: make(map[string]proxy.OutboundHandler),
}
}
func (this *DefaultOutboundHandlerManager) Release() {
}
func (this *DefaultOutboundHandlerManager) GetDefaultHandler() proxy.OutboundHandler {
this.RLock()
defer this.RUnlock()
if this.defaultHandler == nil {
return nil
}
return this.defaultHandler
}
func (this *DefaultOutboundHandlerManager) SetDefaultHandler(handler proxy.OutboundHandler) {
this.Lock()
defer this.Unlock()
this.defaultHandler = handler
}
func (this *DefaultOutboundHandlerManager) GetHandler(tag string) proxy.OutboundHandler {
this.RLock()
defer this.RUnlock()
if handler, found := this.taggedHandler[tag]; found {
return handler
}
return nil
}
func (this *DefaultOutboundHandlerManager) SetHandler(tag string, handler proxy.OutboundHandler) {
this.Lock()
defer this.Unlock()
this.taggedHandler[tag] = handler
}