1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00
v2fly/app/proxyman/proxyman.go
2016-05-18 08:12:04 -07:00

70 lines
1.5 KiB
Go

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
}