1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00
This commit is contained in:
Darien Raymond 2017-12-14 15:02:36 +01:00
parent 6797483fe0
commit 484bdeecc9
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
4 changed files with 8 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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()