Skip to content

Commit

Permalink
move common/log to app/log
Browse files Browse the repository at this point in the history
  • Loading branch information
DarienRaymond committed Feb 1, 2017
1 parent 57fc444 commit f046f33
Show file tree
Hide file tree
Showing 59 changed files with 290 additions and 154 deletions.
2 changes: 2 additions & 0 deletions app/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
// Interface dispatch a packet and possibly further network payload to its destination.
type Interface interface {
DispatchToOutbound(ctx context.Context) ray.InboundRay
Start() error
Close()
}

func FromSpace(space app.Space) Interface {
Expand Down
8 changes: 7 additions & 1 deletion app/dispatcher/impl/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/log"
"v2ray.com/core/app/proxyman"
"v2ray.com/core/app/router"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/ray"
)
Expand All @@ -38,6 +38,12 @@ func NewDefaultDispatcher(ctx context.Context, config *dispatcher.Config) (*Defa
return d, nil
}

func (DefaultDispatcher) Start() error {
return nil
}

func (DefaultDispatcher) Close() {}

func (DefaultDispatcher) Interface() interface{} {
return (*dispatcher.Interface)(nil)
}
Expand Down
2 changes: 1 addition & 1 deletion app/dns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dns
import (
"net"

"v2ray.com/core/common/log"
"v2ray.com/core/app/log"
)

func (v *Config) GetInternalHosts() map[string]net.IP {
Expand Down
2 changes: 2 additions & 0 deletions app/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
// A Server is a DNS server for responding DNS queries.
type Server interface {
Get(domain string) []net.IP
Start() error
Close()
}

func FromSpace(space app.Space) Server {
Expand Down
2 changes: 1 addition & 1 deletion app/dns/server/nameserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/log"
"v2ray.com/core/app/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/transport/internet/udp"
)
Expand Down
8 changes: 7 additions & 1 deletion app/dns/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"v2ray.com/core/app"
"v2ray.com/core/app/dispatcher"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/log"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
v2net "v2ray.com/core/common/net"
)

Expand Down Expand Up @@ -73,6 +73,12 @@ func (CacheServer) Interface() interface{} {
return (*dns.Server)(nil)
}

func (CacheServer) Start() error {
return nil
}

func (CacheServer) Close() {}

// Private: Visible for testing.
func (v *CacheServer) GetCached(domain string) []net.IP {
v.RLock()
Expand Down
2 changes: 1 addition & 1 deletion common/log/access.go → app/log/access.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package log

import (
"v2ray.com/core/common/log/internal"
"v2ray.com/core/app/log/internal"
)

// AccessStatus is the status of an access request from clients.
Expand Down
File renamed without changes.
58 changes: 29 additions & 29 deletions common/log/config.pb.go → app/log/config.pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ func (x LogLevel) String() string {
func (LogLevel) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }

type Config struct {
ErrorLogType LogType `protobuf:"varint,1,opt,name=error_log_type,json=errorLogType,enum=v2ray.core.common.log.LogType" json:"error_log_type,omitempty"`
ErrorLogLevel LogLevel `protobuf:"varint,2,opt,name=error_log_level,json=errorLogLevel,enum=v2ray.core.common.log.LogLevel" json:"error_log_level,omitempty"`
ErrorLogType LogType `protobuf:"varint,1,opt,name=error_log_type,json=errorLogType,enum=v2ray.core.app.log.LogType" json:"error_log_type,omitempty"`
ErrorLogLevel LogLevel `protobuf:"varint,2,opt,name=error_log_level,json=errorLogLevel,enum=v2ray.core.app.log.LogLevel" json:"error_log_level,omitempty"`
ErrorLogPath string `protobuf:"bytes,3,opt,name=error_log_path,json=errorLogPath" json:"error_log_path,omitempty"`
AccessLogType LogType `protobuf:"varint,4,opt,name=access_log_type,json=accessLogType,enum=v2ray.core.common.log.LogType" json:"access_log_type,omitempty"`
AccessLogType LogType `protobuf:"varint,4,opt,name=access_log_type,json=accessLogType,enum=v2ray.core.app.log.LogType" json:"access_log_type,omitempty"`
AccessLogPath string `protobuf:"bytes,5,opt,name=access_log_path,json=accessLogPath" json:"access_log_path,omitempty"`
}

Expand Down Expand Up @@ -121,34 +121,34 @@ func (m *Config) GetAccessLogPath() string {
}

func init() {
proto.RegisterType((*Config)(nil), "v2ray.core.common.log.Config")
proto.RegisterEnum("v2ray.core.common.log.LogType", LogType_name, LogType_value)
proto.RegisterEnum("v2ray.core.common.log.LogLevel", LogLevel_name, LogLevel_value)
proto.RegisterType((*Config)(nil), "v2ray.core.app.log.Config")
proto.RegisterEnum("v2ray.core.app.log.LogType", LogType_name, LogType_value)
proto.RegisterEnum("v2ray.core.app.log.LogLevel", LogLevel_name, LogLevel_value)
}

func init() { proto.RegisterFile("v2ray.com/core/common/log/config.proto", fileDescriptor0) }
func init() { proto.RegisterFile("v2ray.com/core/app/log/config.proto", fileDescriptor0) }

var fileDescriptor0 = []byte{
// 322 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x8c, 0x91, 0x6d, 0x4b, 0xf3, 0x30,
0x14, 0x86, 0xd7, 0x76, 0xaf, 0xd9, 0x5b, 0x08, 0x3c, 0xb0, 0xe7, 0x8b, 0x0e, 0x91, 0x31, 0x06,
0xb6, 0x30, 0xf1, 0x0f, 0xec, 0x4d, 0x84, 0x21, 0x63, 0x08, 0x82, 0x5f, 0x46, 0x17, 0xcf, 0xb2,
0x42, 0x9a, 0x53, 0xd2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0x11, 0x49, 0xa0, 0x2e, 0x6b, 0x90, 0xca,
0xfc, 0x00, 0x2a, 0xa3, 0xde, 0x68, 0x4e, 0xea, 0x5f, 0x8b, 0xb5, 0x48, 0x7d, 0x16, 0xa5, 0xe1,
0x56, 0xc2, 0x2b, 0x2d, 0x59, 0xc8, 0x2c, 0x44, 0x1d, 0xa3, 0x79, 0x0e, 0xb5, 0x8a, 0x94, 0xa0,
0xae, 0xd1, 0x3c, 0xa8, 0x1d, 0x52, 0xcf, 0x10, 0x33, 0xd8, 0xbe, 0x09, 0x5a, 0x9e, 0xdc, 0x90,
0xff, 0x1c, 0xe3, 0xf3, 0x9b, 0x4d, 0x9a, 0xa7, 0x3b, 0xae, 0xcc, 0xb9, 0x5f, 0x3c, 0x89, 0x62,
0x5b, 0xb5, 0xa7, 0xbf, 0xfd, 0x08, 0x00, 0x00, 0xff, 0xff, 0x11, 0x55, 0x7e, 0x04, 0x24, 0x02,
0x00, 0x00,
// 335 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x84, 0x92, 0xcf, 0x4b, 0xc3, 0x30,
0x1c, 0xc5, 0xd7, 0x76, 0x3f, 0xb3, 0x5f, 0x21, 0x07, 0x19, 0xe8, 0x61, 0xa8, 0xc8, 0xd8, 0xa1,
0x85, 0x89, 0x67, 0xd9, 0xba, 0x09, 0xc2, 0x90, 0x31, 0x44, 0xc1, 0xcb, 0xc8, 0x6a, 0x96, 0x15,
0xb2, 0x7c, 0x43, 0x5a, 0x07, 0xfd, 0x7f, 0x3c, 0xf9, 0x57, 0x4a, 0x32, 0x6b, 0x15, 0x15, 0x8f,
0x29, 0xef, 0x7d, 0xde, 0x7b, 0x7c, 0x8b, 0xce, 0xf6, 0x23, 0x4d, 0x33, 0x3f, 0x82, 0x5d, 0x10,
0x81, 0x66, 0x01, 0x55, 0x2a, 0x10, 0xc0, 0x83, 0x08, 0xe4, 0x26, 0xe6,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x9e, 0x51, 0x4c, 0xd9, 0xfa, 0x85, 0xe3, 0xf2, 0xe4, 0x1a, 0x1d,
0x45, 0xb0, 0xfb, 0x65, 0xd6, 0xa4, 0x79, 0xb8, 0xdd, 0xc2, 0xdc, 0xf7, 0xc9, 0x13, 0xc0, 0xdf,
0x5c, 0xf2, 0x30, 0x5a, 0xd2, 0xcc, 0x0f, 0x8d, 0x6c, 0xac, 0x94, 0x59, 0xbe, 0xae, 0xda, 0x1f,
0xe0, 0xf2, 0x3d, 0x00, 0x00, 0xff, 0xff, 0x89, 0x56, 0x54, 0xa7, 0x27, 0x02, 0x00, 0x00,
}
5 changes: 3 additions & 2 deletions common/log/config.proto → app/log/config.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
syntax = "proto3";

package v2ray.core.common.log;
package v2ray.core.app.log;
option csharp_namespace = "V2Ray.Core.App.Log";
option go_package = "log";
option java_package = "com.v2ray.core.common.log";
option java_package = "com.v2ray.core.app.log";
option java_outer_classname = "ConfigProto";

enum LogType {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package internal_test
import (
"testing"

. "v2ray.com/core/common/log/internal"
. "v2ray.com/core/app/log/internal"
"v2ray.com/core/testing/assert"
)

Expand Down
File renamed without changes.
File renamed without changes.
56 changes: 54 additions & 2 deletions common/log/log.go → app/log/log.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package log

import (
"context"

"v2ray.com/core/app"
"v2ray.com/core/app/log/internal"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log/internal"
)

var (
Expand Down Expand Up @@ -77,7 +81,55 @@ func Error(val ...interface{}) {
})
}

func Close() {
type Instance struct {
config *Config
}

func New(ctx context.Context, config *Config) (*Instance, error) {
return &Instance{config: config}, nil
}

func (*Instance) Interface() interface{} {
return (*Instance)(nil)
}

func (g *Instance) Start() error {
config := g.config
if config.AccessLogType == LogType_File {
if err := InitAccessLogger(config.AccessLogPath); err != nil {
return err
}
}

if config.ErrorLogType == LogType_None {
SetLogLevel(LogLevel_Disabled)
} else {
if config.ErrorLogType == LogType_File {
if err := InitErrorLogger(config.ErrorLogPath); err != nil {
return err
}
}
SetLogLevel(config.ErrorLogLevel)
}

return nil
}

func (*Instance) Close() {
streamLoggerInstance.Close()
accessLoggerInstance.Close()
}

func FromSpace(space app.Space) *Instance {
v := space.GetApplication((*Instance)(nil))
if logger, ok := v.(*Instance); ok && logger != nil {
return logger
}
return nil
}

func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
return New(ctx, config.(*Config))
}))
}
2 changes: 1 addition & 1 deletion app/proxyman/inbound/always.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"v2ray.com/core/app/proxyman"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/log"
"v2ray.com/core/app/log"
"v2ray.com/core/common/net"
"v2ray.com/core/proxy"
)
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/inbound/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"v2ray.com/core/app/proxyman"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/log"
"v2ray.com/core/app/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
)
Expand Down
2 changes: 1 addition & 1 deletion app/proxyman/outbound/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"v2ray.com/core/app/proxyman"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
"v2ray.com/core/app/log"
v2net "v2ray.com/core/common/net"
"v2ray.com/core/proxy"
"v2ray.com/core/transport/internet"
Expand Down
4 changes: 4 additions & 0 deletions app/proxyman/outbound/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func (DefaultOutboundHandlerManager) Interface() interface{} {
return (*proxyman.OutboundHandlerManager)(nil)
}

func (DefaultOutboundHandlerManager) Start() error { return nil }

func (DefaultOutboundHandlerManager) Close() {}

func (v *DefaultOutboundHandlerManager) GetDefaultHandler() proxyman.OutboundHandler {
v.RLock()
defer v.RUnlock()
Expand Down
2 changes: 2 additions & 0 deletions app/proxyman/proxyman.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type OutboundHandlerManager interface {
GetHandler(tag string) OutboundHandler
GetDefaultHandler() OutboundHandler
AddHandler(ctx context.Context, config *OutboundHandlerConfig) error
Start() error
Close()
}

type OutboundHandler interface {
Expand Down
8 changes: 7 additions & 1 deletion app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"v2ray.com/core/app"
"v2ray.com/core/app/dns"
"v2ray.com/core/app/log"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
"v2ray.com/core/common/net"
"v2ray.com/core/proxy"
)
Expand Down Expand Up @@ -91,6 +91,12 @@ func (Router) Interface() interface{} {
return (*Router)(nil)
}

func (Router) Start() error {
return nil
}

func (Router) Close() {}

func FromSpace(space app.Space) *Router {
app := space.GetApplication((*Router)(nil))
if app == nil {
Expand Down
24 changes: 20 additions & 4 deletions app/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (

"v2ray.com/core/common"
"v2ray.com/core/common/errors"
"v2ray.com/core/common/log"
)

type Application interface {
Interface() interface{}
Start() error
Close()
}

type InitializationCallback func() error
Expand All @@ -35,6 +36,8 @@ type Space interface {
AddApplication(application Application) error
Initialize() error
OnInitialize(InitializationCallback)
Start() error
Close()
}

type spaceImpl struct {
Expand All @@ -52,9 +55,7 @@ func NewSpace() Space {

func (v *spaceImpl) OnInitialize(f InitializationCallback) {
if v.initialized {
if err := f(); err != nil {
log.Error("Space: error after space initialization: ", err)
}
f()
} else {
v.appInit = append(v.appInit, f)
}
Expand Down Expand Up @@ -88,6 +89,21 @@ func (v *spaceImpl) AddApplication(app Application) error {
return nil
}

func (s *spaceImpl) Start() error {
for _, app := range s.cache {
if err := app.Start(); err != nil {
return err
}
}
return nil
}

func (s *spaceImpl) Close() {
for _, app := range s.cache {
app.Close()
}
}

type contextKey int

const (
Expand Down
2 changes: 1 addition & 1 deletion common/net/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net
import (
"net"

"v2ray.com/core/common/log"
"v2ray.com/core/app/log"
"v2ray.com/core/common/predicate"
)

Expand Down
Loading

0 comments on commit f046f33

Please sign in to comment.