From 484bdeecc979b7cbbd9729fece710be3eaa0f7b0 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 14 Dec 2017 15:02:36 +0100 Subject: [PATCH] comments --- app/policy/config.go | 2 ++ app/policy/manager/manager.go | 2 ++ app/space.go | 2 ++ proxy/shadowsocks/protocol.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/policy/config.go b/app/policy/config.go index 2e07c53b4..350d0751b 100644 --- a/app/policy/config.go +++ b/app/policy/config.go @@ -4,10 +4,12 @@ import ( "time" ) +// Duration converts Second to time.Duration. func (s *Second) Duration() time.Duration { return time.Second * time.Duration(s.Value) } +// OverrideWith overrides current Policy with another one. func (p *Policy) OverrideWith(another *Policy) { if another.Timeout != nil { if another.Timeout.Handshake != nil { diff --git a/app/policy/manager/manager.go b/app/policy/manager/manager.go index 6a339d9aa..e84c462b0 100644 --- a/app/policy/manager/manager.go +++ b/app/policy/manager/manager.go @@ -7,10 +7,12 @@ import ( "v2ray.com/core/common" ) +// Instance is an instance of Policy manager. type Instance struct { levels map[uint32]*policy.Policy } +// New creates new Policy manager instance. func New(ctx context.Context, config *policy.Config) (*Instance, error) { levels := config.Level if levels == nil { diff --git a/app/space.go b/app/space.go index f30775ce2..4a7bc22c4 100644 --- a/app/space.go +++ b/app/space.go @@ -8,12 +8,14 @@ import ( "v2ray.com/core/common/event" ) +// Application is a component that runs in Space. type Application interface { Interface() interface{} Start() error Close() } +// CreateAppFromConfig creates an Application based on its config. Application must have been registered. func CreateAppFromConfig(ctx context.Context, config interface{}) (Application, error) { application, err := common.CreateObject(ctx, config) if err != nil { diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index 68cddf50d..62fe14989 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -22,6 +22,7 @@ const ( AddrTypeDomain = 3 ) +// ReadTCPSession reads a Shadowsocks TCP session from the given reader, returns its header and remaining parts. func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHeader, buf.Reader, error) { rawAccount, err := user.GetTypedAccount() if err != nil { @@ -136,6 +137,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea return request, chunkReader, nil } +// WriteTCPRequest writes Shadowsocks request into the given writer, and returns a writer for body. func WriteTCPRequest(request *protocol.RequestHeader, writer io.Writer) (buf.Writer, error) { user := request.User rawAccount, err := user.GetTypedAccount()