From 0e01e9e9cac5c124f015bc10282985b95283830a Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Sun, 9 Apr 2017 14:49:40 +0200 Subject: [PATCH] comments --- app/dns/dns.go | 1 + app/proxyman/inbound/inbound.go | 17 +++++++++-------- app/proxyman/outbound/outbound.go | 23 ++++++++++++++--------- proxy/socks/client.go | 3 +++ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/app/dns/dns.go b/app/dns/dns.go index 5b96fff6..49b52284 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -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 { diff --git a/app/proxyman/inbound/inbound.go b/app/proxyman/inbound/inbound.go index c22c06b7..964a1491 100644 --- a/app/proxyman/inbound/inbound.go +++ b/app/proxyman/inbound/inbound.go @@ -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) } diff --git a/app/proxyman/outbound/outbound.go b/app/proxyman/outbound/outbound.go index bd8b9cf1..a44d3074 100644 --- a/app/proxyman/outbound/outbound.go +++ b/app/proxyman/outbound/outbound.go @@ -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() diff --git a/proxy/socks/client.go b/proxy/socks/client.go index a804f41d..52a8a214 100644 --- a/proxy/socks/client.go +++ b/proxy/socks/client.go @@ -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 {