From a3f47f4fa284dec2eee22814cc7c02e6deb91601 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Wed, 4 Apr 2018 00:57:44 +0200 Subject: [PATCH] comments --- app/commander/commander.go | 2 ++ app/commander/outbound.go | 5 +++++ app/commander/service.go | 2 ++ app/policy/config.go | 1 + app/proxyman/inbound/inbound.go | 6 +++++- policy.go | 5 ++++- v2ray.go | 1 + 7 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/commander/commander.go b/app/commander/commander.go index 072d38cd9..4a8c80ba7 100644 --- a/app/commander/commander.go +++ b/app/commander/commander.go @@ -13,6 +13,7 @@ import ( "v2ray.com/core/common/signal" ) +// Commander is a V2Ray feature that provides gRPC methods to external clients. type Commander struct { sync.Mutex server *grpc.Server @@ -21,6 +22,7 @@ type Commander struct { ohm core.OutboundHandlerManager } +// NewCommander creates a new Commander based on the given config. func NewCommander(ctx context.Context, config *Config) (*Commander, error) { v := core.MustFromContext(ctx) c := &Commander{ diff --git a/app/commander/outbound.go b/app/commander/outbound.go index f82ae6f28..c55db7478 100644 --- a/app/commander/outbound.go +++ b/app/commander/outbound.go @@ -54,6 +54,7 @@ func (l *OutboundListener) Addr() net.Addr { } } +// CommanderOutbound is a core.OutboundHandler that handles gRPC connections. type CommanderOutbound struct { tag string listener *OutboundListener @@ -61,6 +62,7 @@ type CommanderOutbound struct { closed bool } +// Dispatch implements core.OutboundHandler. func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) { co.access.RLock() @@ -78,10 +80,12 @@ func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) { <-closeSignal.Wait() } +// Tag implements core.OutboundHandler. func (co *CommanderOutbound) Tag() string { return co.tag } +// Start implements common.Runnable. func (co *CommanderOutbound) Start() error { co.access.Lock() co.closed = false @@ -89,6 +93,7 @@ func (co *CommanderOutbound) Start() error { return nil } +// Close implements common.Closable. func (co *CommanderOutbound) Close() error { co.access.Lock() co.closed = true diff --git a/app/commander/service.go b/app/commander/service.go index fb9340db4..4e227c342 100644 --- a/app/commander/service.go +++ b/app/commander/service.go @@ -4,6 +4,8 @@ import ( "google.golang.org/grpc" ) +// Service is a Commander service. type Service interface { + // Register registers the service itself to a gRPC server. Register(*grpc.Server) } diff --git a/app/policy/config.go b/app/policy/config.go index 49cb55303..db5aaa9fa 100644 --- a/app/policy/config.go +++ b/app/policy/config.go @@ -52,6 +52,7 @@ func (p *Policy) overrideWith(another *Policy) { } } +// ToCorePolicy converts this Policy to core.Policy. func (p *Policy) ToCorePolicy() core.Policy { var cp core.Policy if p.Timeout != nil { diff --git a/app/proxyman/inbound/inbound.go b/app/proxyman/inbound/inbound.go index c752216f9..39d339608 100644 --- a/app/proxyman/inbound/inbound.go +++ b/app/proxyman/inbound/inbound.go @@ -50,7 +50,7 @@ func (m *Manager) AddHandler(ctx context.Context, handler core.InboundHandler) e return nil } -// GetHandler returns core.InboundHandlerManager. +// GetHandler implements core.InboundHandlerManager. func (m *Manager) GetHandler(ctx context.Context, tag string) (core.InboundHandler, error) { m.access.RLock() defer m.access.RUnlock() @@ -62,6 +62,7 @@ func (m *Manager) GetHandler(ctx context.Context, tag string) (core.InboundHandl return handler, nil } +// RemoveHandler implements core.InboundHandlerManager. func (m *Manager) RemoveHandler(ctx context.Context, tag string) error { if len(tag) == 0 { return core.ErrNoClue @@ -79,6 +80,7 @@ func (m *Manager) RemoveHandler(ctx context.Context, tag string) error { return core.ErrNoClue } +// Start implements common.Runnable. func (m *Manager) Start() error { m.access.Lock() defer m.access.Unlock() @@ -99,6 +101,7 @@ func (m *Manager) Start() error { return nil } +// Close implements common.Closable. func (m *Manager) Close() error { m.access.Lock() defer m.access.Unlock() @@ -115,6 +118,7 @@ func (m *Manager) Close() error { return nil } +// NewHandler creates a new core.InboundHandler based on the given config. func NewHandler(ctx context.Context, config *core.InboundHandlerConfig) (core.InboundHandler, error) { rawReceiverSettings, err := config.ReceiverSettings.GetInstance() if err != nil { diff --git a/policy.go b/policy.go index d9e0682b9..f8dab11cd 100644 --- a/policy.go +++ b/policy.go @@ -19,8 +19,11 @@ type TimeoutPolicy struct { DownlinkOnly time.Duration } +// StatsPolicy contains settings for stats counters. type StatsPolicy struct { - UserUplink bool + // Whether or not to enable stat counter for user uplink traffic. + UserUplink bool + // Whether or not to enable stat counter for user downlink traffic. UserDownlink bool } diff --git a/v2ray.go b/v2ray.go index 33bc831ab..72c32628c 100755 --- a/v2ray.go +++ b/v2ray.go @@ -211,6 +211,7 @@ func (s *Instance) OutboundHandlerManager() OutboundHandlerManager { return &(s.ohm) } +// Stats returns the StatManager used by this Instance. If StatManager was not registered before, the returned value doesn't work. func (s *Instance) Stats() StatManager { return &(s.stats) }