You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/app/proxyman/outbound/outbound.go

80 lines
1.7 KiB

package outbound
//go:generate go run $GOPATH/src/v2ray.com/core/tools/generrorgen/main.go -pkg outbound -path App,Proxyman,Outbound
import (
8 years ago
"context"
"sync"
8 years ago
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common"
)
8 years ago
// Manager is to manage all outbound handlers.
type Manager struct {
sync.RWMutex
defaultHandler *Handler
taggedHandler map[string]*Handler
}
8 years ago
// New creates a new Manager.
func New(ctx context.Context, config *proxyman.OutboundConfig) (*Manager, error) {
return &Manager{
taggedHandler: make(map[string]*Handler),
8 years ago
}, nil
}
8 years ago
// Interface implements Application.Interface.
func (*Manager) Interface() interface{} {
8 years ago
return (*proxyman.OutboundHandlerManager)(nil)
}
8 years ago
// Start implements Application.Start
func (*Manager) Start() error { return nil }
8 years ago
// Close implements Application.Close
func (*Manager) Close() {}
8 years ago
func (v *Manager) GetDefaultHandler() proxyman.OutboundHandler {
v.RLock()
defer v.RUnlock()
if v.defaultHandler == nil {
return nil
}
return v.defaultHandler
}
8 years ago
func (v *Manager) GetHandler(tag string) proxyman.OutboundHandler {
v.RLock()
defer v.RUnlock()
if handler, found := v.taggedHandler[tag]; found {
return handler
}
return nil
}
8 years ago
func (v *Manager) AddHandler(ctx context.Context, config *proxyman.OutboundHandlerConfig) error {
v.Lock()
defer v.Unlock()
handler, err := NewHandler(ctx, config)
if err != nil {
return err
}
if v.defaultHandler == nil {
v.defaultHandler = handler
}
if len(config.Tag) > 0 {
v.taggedHandler[config.Tag] = handler
}
return nil
}
func init() {
8 years ago
common.Must(common.RegisterConfig((*proxyman.OutboundConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return New(ctx, config.(*proxyman.OutboundConfig))
}))
}