mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
comments
This commit is contained in:
parent
277a08d8a7
commit
0e01e9e9ca
@ -13,6 +13,7 @@ type Server interface {
|
||||
Get(domain string) []net.IP
|
||||
}
|
||||
|
||||
// FromSpace fetches a DNS server from context.
|
||||
func FromSpace(space app.Space) Server {
|
||||
app := space.GetApplication((*Server)(nil))
|
||||
if app == nil {
|
||||
|
@ -9,18 +9,19 @@ import (
|
||||
"v2ray.com/core/common"
|
||||
)
|
||||
|
||||
type DefaultInboundHandlerManager struct {
|
||||
// Manager is to manage all inbound handlers.
|
||||
type Manager struct {
|
||||
handlers []proxyman.InboundHandler
|
||||
taggedHandlers map[string]proxyman.InboundHandler
|
||||
}
|
||||
|
||||
func New(ctx context.Context, config *proxyman.InboundConfig) (*DefaultInboundHandlerManager, error) {
|
||||
return &DefaultInboundHandlerManager{
|
||||
func New(ctx context.Context, config *proxyman.InboundConfig) (*Manager, error) {
|
||||
return &Manager{
|
||||
taggedHandlers: make(map[string]proxyman.InboundHandler),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) AddHandler(ctx context.Context, config *proxyman.InboundHandlerConfig) error {
|
||||
func (m *Manager) AddHandler(ctx context.Context, config *proxyman.InboundHandlerConfig) error {
|
||||
rawReceiverSettings, err := config.ReceiverSettings.GetInstance()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -61,7 +62,7 @@ func (m *DefaultInboundHandlerManager) AddHandler(ctx context.Context, config *p
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) GetHandler(ctx context.Context, tag string) (proxyman.InboundHandler, error) {
|
||||
func (m *Manager) GetHandler(ctx context.Context, tag string) (proxyman.InboundHandler, error) {
|
||||
handler, found := m.taggedHandlers[tag]
|
||||
if !found {
|
||||
return nil, newError("handler not found: ", tag)
|
||||
@ -69,7 +70,7 @@ func (m *DefaultInboundHandlerManager) GetHandler(ctx context.Context, tag strin
|
||||
return handler, nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) Start() error {
|
||||
func (m *Manager) Start() error {
|
||||
for _, handler := range m.handlers {
|
||||
if err := handler.Start(); err != nil {
|
||||
return err
|
||||
@ -78,13 +79,13 @@ func (m *DefaultInboundHandlerManager) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) Close() {
|
||||
func (m *Manager) Close() {
|
||||
for _, handler := range m.handlers {
|
||||
handler.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (m *DefaultInboundHandlerManager) Interface() interface{} {
|
||||
func (m *Manager) Interface() interface{} {
|
||||
return (*proxyman.InboundHandlerManager)(nil)
|
||||
}
|
||||
|
||||
|
@ -10,27 +10,32 @@ import (
|
||||
"v2ray.com/core/common"
|
||||
)
|
||||
|
||||
type DefaultOutboundHandlerManager struct {
|
||||
// Manager is to manage all outbound handlers.
|
||||
type Manager struct {
|
||||
sync.RWMutex
|
||||
defaultHandler *Handler
|
||||
taggedHandler map[string]*Handler
|
||||
}
|
||||
|
||||
func New(ctx context.Context, config *proxyman.OutboundConfig) (*DefaultOutboundHandlerManager, error) {
|
||||
return &DefaultOutboundHandlerManager{
|
||||
// New creates a new Manager.
|
||||
func New(ctx context.Context, config *proxyman.OutboundConfig) (*Manager, error) {
|
||||
return &Manager{
|
||||
taggedHandler: make(map[string]*Handler),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (*DefaultOutboundHandlerManager) Interface() interface{} {
|
||||
// Interface implements Application.Interface.
|
||||
func (*Manager) Interface() interface{} {
|
||||
return (*proxyman.OutboundHandlerManager)(nil)
|
||||
}
|
||||
|
||||
func (*DefaultOutboundHandlerManager) Start() error { return nil }
|
||||
// Start implements Application.Start
|
||||
func (*Manager) Start() error { return nil }
|
||||
|
||||
func (*DefaultOutboundHandlerManager) Close() {}
|
||||
// Close implements Application.Close
|
||||
func (*Manager) Close() {}
|
||||
|
||||
func (v *DefaultOutboundHandlerManager) GetDefaultHandler() proxyman.OutboundHandler {
|
||||
func (v *Manager) GetDefaultHandler() proxyman.OutboundHandler {
|
||||
v.RLock()
|
||||
defer v.RUnlock()
|
||||
if v.defaultHandler == nil {
|
||||
@ -39,7 +44,7 @@ func (v *DefaultOutboundHandlerManager) GetDefaultHandler() proxyman.OutboundHan
|
||||
return v.defaultHandler
|
||||
}
|
||||
|
||||
func (v *DefaultOutboundHandlerManager) GetHandler(tag string) proxyman.OutboundHandler {
|
||||
func (v *Manager) GetHandler(tag string) proxyman.OutboundHandler {
|
||||
v.RLock()
|
||||
defer v.RUnlock()
|
||||
if handler, found := v.taggedHandler[tag]; found {
|
||||
@ -48,7 +53,7 @@ func (v *DefaultOutboundHandlerManager) GetHandler(tag string) proxyman.Outbound
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *DefaultOutboundHandlerManager) AddHandler(ctx context.Context, config *proxyman.OutboundHandlerConfig) error {
|
||||
func (v *Manager) AddHandler(ctx context.Context, config *proxyman.OutboundHandlerConfig) error {
|
||||
v.Lock()
|
||||
defer v.Unlock()
|
||||
|
||||
|
@ -16,10 +16,12 @@ import (
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
|
||||
// Client is a Socks5 client.
|
||||
type Client struct {
|
||||
serverPicker protocol.ServerPicker
|
||||
}
|
||||
|
||||
// NewClient create a new Socks5 client based on the given config.
|
||||
func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
||||
serverList := protocol.NewServerList()
|
||||
for _, rec := range config.Server {
|
||||
@ -32,6 +34,7 @@ func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
|
||||
return client, nil
|
||||
}
|
||||
|
||||
// Process implements proxy.Outbound.Process.
|
||||
func (c *Client) Process(ctx context.Context, ray ray.OutboundRay, dialer proxy.Dialer) error {
|
||||
destination, ok := proxy.TargetFromContext(ctx)
|
||||
if !ok {
|
||||
|
Loading…
Reference in New Issue
Block a user