README ¶
Project V
Project V is a set of network tools that help you to build your own computer network. It secures your network connections and thus protects your privacy. See our website for more information.
License
Credits
This repo relies on the following third-party projects:
- In production:
- For testing only:
Documentation ¶
Overview ¶
Package core provides an entry point to use V2Ray core functionalities.
V2Ray makes it possible to accept incoming network connections with certain protocol, process the data, and send them through another connection with the same or a difference protocol on demand.
It may be configured to work with multiple protocols at the same time, and uses the internal router to tunnel through different inbound and outbound connections.
Index ¶
- Constants
- Variables
- func ContextWithBufferPolicy(ctx context.Context, p BufferPolicy) context.Context
- func CreateObject(v *Instance, config interface{}) (interface{}, error)
- func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error)
- func LoadPlugins() error
- func RegisterConfigLoader(format *ConfigFormat) error
- func Version() string
- func VersionStatement() []string
- type BufferPolicy
- type Config
- func (*Config) Descriptor() ([]byte, []int)
- func (m *Config) GetApp() []*serial.TypedMessage
- func (m *Config) GetExtension() []*serial.TypedMessage
- func (m *Config) GetInbound() []*InboundHandlerConfig
- func (m *Config) GetOutbound() []*OutboundHandlerConfig
- func (m *Config) GetTransport() *transport.Config
- func (*Config) ProtoMessage()
- func (m *Config) Reset()
- func (m *Config) String() string
- func (m *Config) XXX_DiscardUnknown()
- func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *Config) XXX_Merge(src proto.Message)
- func (m *Config) XXX_Size() int
- func (m *Config) XXX_Unmarshal(b []byte) error
- type ConfigFormat
- type ConfigLoader
- type DNSClient
- type Dispatcher
- type Feature
- type GetMetadataFunc
- type InboundHandler
- type InboundHandlerConfig
- func (*InboundHandlerConfig) Descriptor() ([]byte, []int)
- func (m *InboundHandlerConfig) GetProxySettings() *serial.TypedMessage
- func (m *InboundHandlerConfig) GetReceiverSettings() *serial.TypedMessage
- func (m *InboundHandlerConfig) GetTag() string
- func (*InboundHandlerConfig) ProtoMessage()
- func (m *InboundHandlerConfig) Reset()
- func (m *InboundHandlerConfig) String() string
- func (m *InboundHandlerConfig) XXX_DiscardUnknown()
- func (m *InboundHandlerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *InboundHandlerConfig) XXX_Merge(src proto.Message)
- func (m *InboundHandlerConfig) XXX_Size() int
- func (m *InboundHandlerConfig) XXX_Unmarshal(b []byte) error
- type InboundHandlerManager
- type Instance
- func (s *Instance) Close() error
- func (s *Instance) DNSClient() DNSClient
- func (s *Instance) Dispatcher() Dispatcher
- func (s *Instance) GetFeature(featureType interface{}) Feature
- func (s *Instance) ID() uuid.UUID
- func (s *Instance) InboundHandlerManager() InboundHandlerManager
- func (s *Instance) OutboundHandlerManager() OutboundHandlerManager
- func (s *Instance) PolicyManager() PolicyManager
- func (s *Instance) RegisterFeature(feature interface{}, instance Feature) error
- func (s *Instance) Router() Router
- func (s *Instance) Start() error
- func (s *Instance) Stats() StatManager
- type Link
- type OutboundHandler
- type OutboundHandlerConfig
- func (*OutboundHandlerConfig) Descriptor() ([]byte, []int)
- func (m *OutboundHandlerConfig) GetComment() string
- func (m *OutboundHandlerConfig) GetExpire() int64
- func (m *OutboundHandlerConfig) GetProxySettings() *serial.TypedMessage
- func (m *OutboundHandlerConfig) GetSenderSettings() *serial.TypedMessage
- func (m *OutboundHandlerConfig) GetTag() string
- func (*OutboundHandlerConfig) ProtoMessage()
- func (m *OutboundHandlerConfig) Reset()
- func (m *OutboundHandlerConfig) String() string
- func (m *OutboundHandlerConfig) XXX_DiscardUnknown()
- func (m *OutboundHandlerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (dst *OutboundHandlerConfig) XXX_Merge(src proto.Message)
- func (m *OutboundHandlerConfig) XXX_Size() int
- func (m *OutboundHandlerConfig) XXX_Unmarshal(b []byte) error
- type OutboundHandlerManager
- type PluginMetadata
- type Policy
- type PolicyManager
- type Router
- type Server
- type StatCounter
- type StatManager
- type StatsPolicy
- type SystemPolicy
- type SystemStatsPolicy
- type TimeoutPolicy
Constants ¶
const GetMetadataFuncName = "GetPluginMetadata"
GetMetadataFuncName is the name of the function in the plugin to return PluginMetadata.
Variables ¶
var ( // ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route. ErrNoClue = errors.New("not enough information for making a decision") )
Functions ¶
func ContextWithBufferPolicy ¶
func ContextWithBufferPolicy(ctx context.Context, p BufferPolicy) context.Context
func CreateObject ¶
CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.
func Dial ¶
Dial provides an easy way for upstream caller to create net.Conn through V2Ray. It dispatches the request to the given destination by the given V2Ray instance. Since it is under a proxy context, the LocalAddr() and RemoteAddr() in returned net.Conn will not show real addresses being used for communication.
func LoadPlugins ¶
func LoadPlugins() error
LoadPlugins loads all possible plugins in the 'plugin' directory.
func RegisterConfigLoader ¶
func RegisterConfigLoader(format *ConfigFormat) error
RegisterConfigLoader add a new ConfigLoader.
func Version ¶
func Version() string
Version returns V2Ray's version as a string, in the form of "x.y.z" where x, y and z are numbers. ".z" part may be omitted in regular releases.
func VersionStatement ¶
func VersionStatement() []string
VersionStatement returns a list of strings representing the full version info.
Types ¶
type BufferPolicy ¶
type BufferPolicy struct { // Size of buffer per connection, in bytes. -1 for unlimited buffer. PerConnection int32 }
BufferPolicy contains settings for internal buffer.
func BufferPolicyFromContext ¶
func BufferPolicyFromContext(ctx context.Context) BufferPolicy
type Config ¶
type Config struct { // Inbound handler configurations. Must have at least one item. Inbound []*InboundHandlerConfig `protobuf:"bytes,1,rep,name=inbound,proto3" json:"inbound,omitempty"` // Outbound handler configurations. Must have at least one item. The first item is used as default for routing. Outbound []*OutboundHandlerConfig `protobuf:"bytes,2,rep,name=outbound,proto3" json:"outbound,omitempty"` // App is for configurations of all features in V2Ray. A feature must implement the Feature interface, and its config type must be registered through common.RegisterConfig. App []*serial.TypedMessage `protobuf:"bytes,4,rep,name=app,proto3" json:"app,omitempty"` // Transport settings. Transport *transport.Config `protobuf:"bytes,5,opt,name=transport,proto3" json:"transport,omitempty"` // Configuration for extensions. The config may not work if corresponding extension is not loaded into V2Ray. // V2Ray will ignore such config during initialization. Extension []*serial.TypedMessage `protobuf:"bytes,6,rep,name=extension,proto3" json:"extension,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
Config is the master config of V2Ray. V2Ray takes this config as input and functions accordingly.
func LoadConfig ¶
LoadConfig loads config with given format from given source.
func (*Config) Descriptor ¶
func (*Config) GetApp ¶
func (m *Config) GetApp() []*serial.TypedMessage
func (*Config) GetExtension ¶
func (m *Config) GetExtension() []*serial.TypedMessage
func (*Config) GetInbound ¶
func (m *Config) GetInbound() []*InboundHandlerConfig
func (*Config) GetOutbound ¶
func (m *Config) GetOutbound() []*OutboundHandlerConfig
func (*Config) GetTransport ¶
func (*Config) ProtoMessage ¶
func (*Config) ProtoMessage()
func (*Config) XXX_DiscardUnknown ¶
func (m *Config) XXX_DiscardUnknown()
func (*Config) XXX_Marshal ¶
func (*Config) XXX_Unmarshal ¶
type ConfigFormat ¶
type ConfigFormat struct { Name string Extension []string Loader ConfigLoader }
ConfigFormat is a configurable format of V2Ray config file.
type ConfigLoader ¶
ConfigLoader is a utility to load V2Ray config from external source.
type Dispatcher ¶
type Dispatcher interface { Feature // Dispatch returns a Ray for transporting data for the given request. Dispatch(ctx context.Context, dest net.Destination) (*Link, error) }
Dispatcher is a feature that dispatches inbound requests to outbound handlers based on rules. Dispatcher is required to be registered in a V2Ray instance to make V2Ray function properly.
type Feature ¶
Feature is the interface for V2Ray features. All features must implement this interface. All existing features have an implementation in app directory. These features can be replaced by third-party ones.
type GetMetadataFunc ¶
type GetMetadataFunc func() PluginMetadata
GetMetadataFunc is the type of the function in the plugin to return PluginMetadata.
type InboundHandler ¶
type InboundHandler interface { common.Runnable // The tag of this handler. Tag() string // Deprecated. Do not use in new code. GetRandomInboundProxy() (interface{}, net.Port, int) }
InboundHandler is the interface for handlers that process inbound connections.
type InboundHandlerConfig ¶
type InboundHandlerConfig struct { // Tag of the inbound handler. The tag must be unique among all inbound handlers Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"` // Settings for how this inbound proxy is handled. ReceiverSettings *serial.TypedMessage `protobuf:"bytes,2,opt,name=receiver_settings,json=receiverSettings,proto3" json:"receiver_settings,omitempty"` // Settings for inbound proxy. Must be one of the inbound proxies. ProxySettings *serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings,proto3" json:"proxy_settings,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
InboundHandlerConfig is the configuration for inbound handler.
func (*InboundHandlerConfig) Descriptor ¶
func (*InboundHandlerConfig) Descriptor() ([]byte, []int)
func (*InboundHandlerConfig) GetProxySettings ¶
func (m *InboundHandlerConfig) GetProxySettings() *serial.TypedMessage
func (*InboundHandlerConfig) GetReceiverSettings ¶
func (m *InboundHandlerConfig) GetReceiverSettings() *serial.TypedMessage
func (*InboundHandlerConfig) GetTag ¶
func (m *InboundHandlerConfig) GetTag() string
func (*InboundHandlerConfig) ProtoMessage ¶
func (*InboundHandlerConfig) ProtoMessage()
func (*InboundHandlerConfig) Reset ¶
func (m *InboundHandlerConfig) Reset()
func (*InboundHandlerConfig) String ¶
func (m *InboundHandlerConfig) String() string
func (*InboundHandlerConfig) XXX_DiscardUnknown ¶
func (m *InboundHandlerConfig) XXX_DiscardUnknown()
func (*InboundHandlerConfig) XXX_Marshal ¶
func (m *InboundHandlerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*InboundHandlerConfig) XXX_Merge ¶
func (dst *InboundHandlerConfig) XXX_Merge(src proto.Message)
func (*InboundHandlerConfig) XXX_Size ¶
func (m *InboundHandlerConfig) XXX_Size() int
func (*InboundHandlerConfig) XXX_Unmarshal ¶
func (m *InboundHandlerConfig) XXX_Unmarshal(b []byte) error
type InboundHandlerManager ¶
type InboundHandlerManager interface { Feature // GetHandlers returns an InboundHandler for the given tag. GetHandler(ctx context.Context, tag string) (InboundHandler, error) // AddHandler adds the given handler into this InboundHandlerManager. AddHandler(ctx context.Context, handler InboundHandler) error // RemoveHandler removes a handler from InboundHandlerManager. RemoveHandler(ctx context.Context, tag string) error }
InboundHandlerManager is a feature that manages InboundHandlers.
type Instance ¶
type Instance struct {
// contains filtered or unexported fields
}
Instance combines all functionalities in V2Ray.
func FromContext ¶
FromContext returns an Instance from the given context, or nil if the context doesn't contain one.
func MustFromContext ¶
MustFromContext returns an Instance from the given context, or panics if not present.
func New ¶
New returns a new V2Ray instance based on given configuration. The instance is not started at this point. To ensure V2Ray instance works properly, the config must contain one Dispatcher, one InboundHandlerManager and one OutboundHandlerManager. Other features are optional.
func (*Instance) DNSClient ¶
DNSClient returns the DNSClient used by this Instance. The returned DNSClient is always functional.
func (*Instance) Dispatcher ¶
func (s *Instance) Dispatcher() Dispatcher
Dispatcher returns the Dispatcher used by this Instance. If Dispatcher was not registered before, the returned value doesn't work, although it is not nil.
func (*Instance) GetFeature ¶
GetFeature returns a feature that was registered in this Instance. Nil if not found. The returned Feature must implement common.HasType and whose type equals to the given feature type.
func (*Instance) InboundHandlerManager ¶
func (s *Instance) InboundHandlerManager() InboundHandlerManager
InboundHandlerManager returns the InboundHandlerManager used by this Instance. If InboundHandlerManager was not registered before, the returned value doesn't work.
func (*Instance) OutboundHandlerManager ¶
func (s *Instance) OutboundHandlerManager() OutboundHandlerManager
OutboundHandlerManager returns the OutboundHandlerManager used by this Instance. If OutboundHandlerManager was not registered before, the returned value doesn't work.
func (*Instance) PolicyManager ¶
func (s *Instance) PolicyManager() PolicyManager
PolicyManager returns the PolicyManager used by this Instance. The returned PolicyManager is always functional.
func (*Instance) RegisterFeature ¶
RegisterFeature registers the given feature into V2Ray. If feature is one of the following types, the corresponding feature in this Instance will be replaced: DNSClient, PolicyManager, Router, Dispatcher, InboundHandlerManager, OutboundHandlerManager.
func (*Instance) Router ¶
Router returns the Router used by this Instance. The returned Router is always functional.
func (*Instance) Start ¶
Start starts the V2Ray instance, including all registered features. When Start returns error, the state of the instance is unknown. A V2Ray instance can be started only once. Upon closing, the instance is not guaranteed to start again.
func (*Instance) Stats ¶
func (s *Instance) Stats() StatManager
Stats returns the StatManager used by this Instance. If StatManager was not registered before, the returned value doesn't work.
type OutboundHandler ¶
type OutboundHandler interface { common.Runnable Tag() string Dispatch(ctx context.Context, link *Link) }
OutboundHandler is the interface for handlers that process outbound connections.
type OutboundHandlerConfig ¶
type OutboundHandlerConfig struct { // Tag of this outbound handler. Tag string `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"` // Settings for how to dial connection for this outbound handler. SenderSettings *serial.TypedMessage `protobuf:"bytes,2,opt,name=sender_settings,json=senderSettings,proto3" json:"sender_settings,omitempty"` // Settings for this outbound proxy. Must be one of the outbound proxies. ProxySettings *serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings,proto3" json:"proxy_settings,omitempty"` // If not zero, this outbound will be expired in seconds. Not used for now. Expire int64 `protobuf:"varint,4,opt,name=expire,proto3" json:"expire,omitempty"` // Comment of this outbound handler. Not used for now. Comment string `protobuf:"bytes,5,opt,name=comment,proto3" json:"comment,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
OutboundHandlerConfig is the configuration for outbound handler.
func (*OutboundHandlerConfig) Descriptor ¶
func (*OutboundHandlerConfig) Descriptor() ([]byte, []int)
func (*OutboundHandlerConfig) GetComment ¶
func (m *OutboundHandlerConfig) GetComment() string
func (*OutboundHandlerConfig) GetExpire ¶
func (m *OutboundHandlerConfig) GetExpire() int64
func (*OutboundHandlerConfig) GetProxySettings ¶
func (m *OutboundHandlerConfig) GetProxySettings() *serial.TypedMessage
func (*OutboundHandlerConfig) GetSenderSettings ¶
func (m *OutboundHandlerConfig) GetSenderSettings() *serial.TypedMessage
func (*OutboundHandlerConfig) GetTag ¶
func (m *OutboundHandlerConfig) GetTag() string
func (*OutboundHandlerConfig) ProtoMessage ¶
func (*OutboundHandlerConfig) ProtoMessage()
func (*OutboundHandlerConfig) Reset ¶
func (m *OutboundHandlerConfig) Reset()
func (*OutboundHandlerConfig) String ¶
func (m *OutboundHandlerConfig) String() string
func (*OutboundHandlerConfig) XXX_DiscardUnknown ¶
func (m *OutboundHandlerConfig) XXX_DiscardUnknown()
func (*OutboundHandlerConfig) XXX_Marshal ¶
func (m *OutboundHandlerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*OutboundHandlerConfig) XXX_Merge ¶
func (dst *OutboundHandlerConfig) XXX_Merge(src proto.Message)
func (*OutboundHandlerConfig) XXX_Size ¶
func (m *OutboundHandlerConfig) XXX_Size() int
func (*OutboundHandlerConfig) XXX_Unmarshal ¶
func (m *OutboundHandlerConfig) XXX_Unmarshal(b []byte) error
type OutboundHandlerManager ¶
type OutboundHandlerManager interface { Feature // GetHandler returns an OutboundHandler for the given tag. GetHandler(tag string) OutboundHandler // GetDefaultHandler returns the default OutboundHandler. It is usually the first OutboundHandler specified in the configuration. GetDefaultHandler() OutboundHandler // AddHandler adds a handler into this OutboundHandlerManager. AddHandler(ctx context.Context, handler OutboundHandler) error // RemoveHandler removes a handler from OutboundHandlerManager. RemoveHandler(ctx context.Context, tag string) error }
OutboundHandlerManager is a feature that manages OutboundHandlers.
type PluginMetadata ¶
type PluginMetadata struct { // Name of the plugin Name string }
PluginMetadata contains some brief information regarding a plugin.
type Policy ¶
type Policy struct { Timeouts TimeoutPolicy // Timeout settings Stats StatsPolicy Buffer BufferPolicy }
Policy is session based settings for controlling V2Ray requests. It contains various settings (or limits) that may differ for different users in the context.
func DefaultPolicy ¶
func DefaultPolicy() Policy
DefaultPolicy returns the Policy when user is not specified.
type PolicyManager ¶
type PolicyManager interface { Feature // ForLevel returns the Policy for the given user level. ForLevel(level uint32) Policy // ForSystem returns the Policy for V2Ray system. ForSystem() SystemPolicy }
PolicyManager is a feature that provides Policy for the given user by its id or level.
type Router ¶
type Router interface { Feature // PickRoute returns a tag of an OutboundHandler based on the given context. PickRoute(ctx context.Context) (string, error) }
Router is a feature to choose an outbound tag for the given request.
type Server ¶
Server is an instance of V2Ray. At any time, there must be at most one Server instance running. Deprecated. Use Instance directly.
type StatCounter ¶
func GetOrRegisterStatCounter ¶
func GetOrRegisterStatCounter(m StatManager, name string) (StatCounter, error)
GetOrRegisterStatCounter tries to get the StatCounter first. If not exist, it then tries to create a new counter.
type StatManager ¶
type StatManager interface { Feature RegisterCounter(string) (StatCounter, error) GetCounter(string) StatCounter }
type StatsPolicy ¶
type StatsPolicy struct { // 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 }
StatsPolicy contains settings for stats counters.
type SystemPolicy ¶
type SystemPolicy struct { Stats SystemStatsPolicy Buffer BufferPolicy }
SystemPolicy contains policy settings at system level.
type SystemStatsPolicy ¶
type SystemStatsPolicy struct { // Whether or not to enable stat counter for uplink traffic in inbound handlers. InboundUplink bool // Whether or not to enable stat counter for downlink traffic in inbound handlers. InboundDownlink bool }
SystemStatsPolicy contains stat policy settings on system level.
type TimeoutPolicy ¶
type TimeoutPolicy struct { // Timeout for handshake phase in a connection. Handshake time.Duration // Timeout for connection being idle, i.e., there is no egress or ingress traffic in this connection. ConnectionIdle time.Duration // Timeout for an uplink only connection, i.e., the downlink of the connection has been closed. UplinkOnly time.Duration // Timeout for an downlink only connection, i.e., the uplink of the connection has been closed. DownlinkOnly time.Duration }
TimeoutPolicy contains limits for connection timeout.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
dns
Package dns is an implementation of core.DNS feature.
|
Package dns is an implementation of core.DNS feature. |
policy
Package policy is an implementation of core.PolicyManager feature.
|
Package policy is an implementation of core.PolicyManager feature. |
proxyman
Package proxyman defines applications for managing inbound and outbound proxies.
|
Package proxyman defines applications for managing inbound and outbound proxies. |
Package common contains common utilities that are shared among other packages.
|
Package common contains common utilities that are shared among other packages. |
buf
Package buf provides a light-weight memory allocation mechanism.
|
Package buf provides a light-weight memory allocation mechanism. |
crypto
Package crypto provides common crypto libraries for V2Ray.
|
Package crypto provides common crypto libraries for V2Ray. |
dice
Package dice contains common functions to generate random number.
|
Package dice contains common functions to generate random number. |
errors
Package errors is a drop-in replacement for Golang lib 'errors'.
|
Package errors is a drop-in replacement for Golang lib 'errors'. |
net
Package net is a drop-in replacement to Golang's net package, with some more functionalities.
|
Package net is a drop-in replacement to Golang's net package, with some more functionalities. |
session
Package session provides functions for sessions of incoming requests.
|
Package session provides functions for sessions of incoming requests. |
Package proxy contains all proxies used by V2Ray.
|
Package proxy contains all proxies used by V2Ray. |
blackhole
Package blackhole is an outbound handler that blocks all connections.
|
Package blackhole is an outbound handler that blocks all connections. |
shadowsocks
Package shadowsocks provides compatible functionality to Shadowsocks.
|
Package shadowsocks provides compatible functionality to Shadowsocks. |
socks
Package socks provides implements of Socks protocol 4, 4a and 5.
|
Package socks provides implements of Socks protocol 4, 4a and 5. |
vmess
Package vmess contains the implementation of VMess protocol and transportation.
|
Package vmess contains the implementation of VMess protocol and transportation. |
testing
|
|
internet/kcp
Package kcp - A Fast and Reliable ARQ Protocol
|
Package kcp - A Fast and Reliable ARQ Protocol |
internet/websocket
Package websocket implements Websocket transport
|
Package websocket implements Websocket transport |