mirror of https://github.com/v2fly/v2ray-core.git
comments
This commit is contained in:
parent
9f198d7e3d
commit
a3f47f4fa2
|
@ -13,6 +13,7 @@ import (
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Commander is a V2Ray feature that provides gRPC methods to external clients.
|
||||||
type Commander struct {
|
type Commander struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
server *grpc.Server
|
server *grpc.Server
|
||||||
|
@ -21,6 +22,7 @@ type Commander struct {
|
||||||
ohm core.OutboundHandlerManager
|
ohm core.OutboundHandlerManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCommander creates a new Commander based on the given config.
|
||||||
func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
|
func NewCommander(ctx context.Context, config *Config) (*Commander, error) {
|
||||||
v := core.MustFromContext(ctx)
|
v := core.MustFromContext(ctx)
|
||||||
c := &Commander{
|
c := &Commander{
|
||||||
|
|
|
@ -54,6 +54,7 @@ func (l *OutboundListener) Addr() net.Addr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommanderOutbound is a core.OutboundHandler that handles gRPC connections.
|
||||||
type CommanderOutbound struct {
|
type CommanderOutbound struct {
|
||||||
tag string
|
tag string
|
||||||
listener *OutboundListener
|
listener *OutboundListener
|
||||||
|
@ -61,6 +62,7 @@ type CommanderOutbound struct {
|
||||||
closed bool
|
closed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dispatch implements core.OutboundHandler.
|
||||||
func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) {
|
func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) {
|
||||||
co.access.RLock()
|
co.access.RLock()
|
||||||
|
|
||||||
|
@ -78,10 +80,12 @@ func (co *CommanderOutbound) Dispatch(ctx context.Context, r ray.OutboundRay) {
|
||||||
<-closeSignal.Wait()
|
<-closeSignal.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tag implements core.OutboundHandler.
|
||||||
func (co *CommanderOutbound) Tag() string {
|
func (co *CommanderOutbound) Tag() string {
|
||||||
return co.tag
|
return co.tag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start implements common.Runnable.
|
||||||
func (co *CommanderOutbound) Start() error {
|
func (co *CommanderOutbound) Start() error {
|
||||||
co.access.Lock()
|
co.access.Lock()
|
||||||
co.closed = false
|
co.closed = false
|
||||||
|
@ -89,6 +93,7 @@ func (co *CommanderOutbound) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close implements common.Closable.
|
||||||
func (co *CommanderOutbound) Close() error {
|
func (co *CommanderOutbound) Close() error {
|
||||||
co.access.Lock()
|
co.access.Lock()
|
||||||
co.closed = true
|
co.closed = true
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Service is a Commander service.
|
||||||
type Service interface {
|
type Service interface {
|
||||||
|
// Register registers the service itself to a gRPC server.
|
||||||
Register(*grpc.Server)
|
Register(*grpc.Server)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ func (p *Policy) overrideWith(another *Policy) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToCorePolicy converts this Policy to core.Policy.
|
||||||
func (p *Policy) ToCorePolicy() core.Policy {
|
func (p *Policy) ToCorePolicy() core.Policy {
|
||||||
var cp core.Policy
|
var cp core.Policy
|
||||||
if p.Timeout != nil {
|
if p.Timeout != nil {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (m *Manager) AddHandler(ctx context.Context, handler core.InboundHandler) e
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHandler returns core.InboundHandlerManager.
|
// GetHandler implements core.InboundHandlerManager.
|
||||||
func (m *Manager) GetHandler(ctx context.Context, tag string) (core.InboundHandler, error) {
|
func (m *Manager) GetHandler(ctx context.Context, tag string) (core.InboundHandler, error) {
|
||||||
m.access.RLock()
|
m.access.RLock()
|
||||||
defer m.access.RUnlock()
|
defer m.access.RUnlock()
|
||||||
|
@ -62,6 +62,7 @@ func (m *Manager) GetHandler(ctx context.Context, tag string) (core.InboundHandl
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveHandler implements core.InboundHandlerManager.
|
||||||
func (m *Manager) RemoveHandler(ctx context.Context, tag string) error {
|
func (m *Manager) RemoveHandler(ctx context.Context, tag string) error {
|
||||||
if len(tag) == 0 {
|
if len(tag) == 0 {
|
||||||
return core.ErrNoClue
|
return core.ErrNoClue
|
||||||
|
@ -79,6 +80,7 @@ func (m *Manager) RemoveHandler(ctx context.Context, tag string) error {
|
||||||
return core.ErrNoClue
|
return core.ErrNoClue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start implements common.Runnable.
|
||||||
func (m *Manager) Start() error {
|
func (m *Manager) Start() error {
|
||||||
m.access.Lock()
|
m.access.Lock()
|
||||||
defer m.access.Unlock()
|
defer m.access.Unlock()
|
||||||
|
@ -99,6 +101,7 @@ func (m *Manager) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close implements common.Closable.
|
||||||
func (m *Manager) Close() error {
|
func (m *Manager) Close() error {
|
||||||
m.access.Lock()
|
m.access.Lock()
|
||||||
defer m.access.Unlock()
|
defer m.access.Unlock()
|
||||||
|
@ -115,6 +118,7 @@ func (m *Manager) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewHandler creates a new core.InboundHandler based on the given config.
|
||||||
func NewHandler(ctx context.Context, config *core.InboundHandlerConfig) (core.InboundHandler, error) {
|
func NewHandler(ctx context.Context, config *core.InboundHandlerConfig) (core.InboundHandler, error) {
|
||||||
rawReceiverSettings, err := config.ReceiverSettings.GetInstance()
|
rawReceiverSettings, err := config.ReceiverSettings.GetInstance()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -19,8 +19,11 @@ type TimeoutPolicy struct {
|
||||||
DownlinkOnly time.Duration
|
DownlinkOnly time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StatsPolicy contains settings for stats counters.
|
||||||
type StatsPolicy struct {
|
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
|
UserDownlink bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
v2ray.go
1
v2ray.go
|
@ -211,6 +211,7 @@ func (s *Instance) OutboundHandlerManager() OutboundHandlerManager {
|
||||||
return &(s.ohm)
|
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 {
|
func (s *Instance) Stats() StatManager {
|
||||||
return &(s.stats)
|
return &(s.stats)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue