core: v2ray.com/core Index | Files | Directories

package core

import "v2ray.com/core"

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

Package Files

annotations.go config.go config.pb.go context.go core.go errors.generated.go functions.go mocks.go proto.go v2ray.go

func AddInboundHandler Uses

func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error

func AddOutboundHandler Uses

func AddOutboundHandler(server *Instance, config *OutboundHandlerConfig) error

func CreateObject Uses

func CreateObject(v *Instance, config interface{}) (interface{}, error)

CreateObject creates a new object based on the given V2Ray instance and config. The V2Ray instance may be nil.

func Dial Uses

func Dial(ctx context.Context, v *Instance, dest net.Destination) (net.Conn, error)

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.

v2ray:api:stable

func DialUDP Uses

func DialUDP(ctx context.Context, v *Instance) (net.PacketConn, error)

DialUDP provides a way to exchange UDP packets through V2Ray instance to remote servers. Since it is under a proxy context, the LocalAddr() in returned PacketConn will not show the real address.

TODO: SetDeadline() / SetReadDeadline() / SetWriteDeadline() are not implemented.

v2ray:api:beta

func RegisterConfigLoader Uses

func RegisterConfigLoader(format *ConfigFormat) error

RegisterConfigLoader add a new ConfigLoader.

func RequireFeatures Uses

func RequireFeatures(ctx context.Context, callback interface{}) error

RequireFeatures is a helper function to require features from Instance in context. See Instance.RequireFeatures for more information.

func ServerType Uses

func ServerType() interface{}

ServerType returns the type of the server.

func Version Uses

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 Uses

func VersionStatement() []string

VersionStatement returns a list of strings representing the full version info.

type Annotation Uses

type Annotation struct {
    // API is for types or functions that can be used in other libs. Possible values are:
    //
    // * v2ray:api:beta for types or functions that are ready for use, but maybe changed in the future.
    // * v2ray:api:stable for types or functions with guarantee of backward compatibility.
    // * v2ray:api:deprecated for types or functions that should not be used anymore.
    //
    // Types or functions without api annotation should not be used externally.
    API string
}

Annotation is a concept in V2Ray. This struct is only for documentation. It is not used anywhere. Annotations begin with "v2ray:" in comment, as metadata of functions or types.

type Config Uses

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.
    // Deprecated. Each inbound and outbound should choose their own transport config.
    // Date to remove: 2020-01-13
    Transport *transport.Config `protobuf:"bytes,5,opt,name=transport,proto3" json:"transport,omitempty"` // Deprecated: Do not use.
    // 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 Uses

func LoadConfig(formatName string, filename string, input io.Reader) (*Config, error)

LoadConfig loads config with given format from given source.

func (*Config) Descriptor Uses

func (*Config) Descriptor() ([]byte, []int)

func (*Config) GetApp Uses

func (m *Config) GetApp() []*serial.TypedMessage

func (*Config) GetExtension Uses

func (m *Config) GetExtension() []*serial.TypedMessage

func (*Config) GetInbound Uses

func (m *Config) GetInbound() []*InboundHandlerConfig

func (*Config) GetOutbound Uses

func (m *Config) GetOutbound() []*OutboundHandlerConfig

func (*Config) GetTransport Uses

func (m *Config) GetTransport() *transport.Config

Deprecated: Do not use.

func (*Config) ProtoMessage Uses

func (*Config) ProtoMessage()

func (*Config) Reset Uses

func (m *Config) Reset()

func (*Config) String Uses

func (m *Config) String() string

func (*Config) XXX_DiscardUnknown Uses

func (m *Config) XXX_DiscardUnknown()

func (*Config) XXX_Marshal Uses

func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Config) XXX_Merge Uses

func (m *Config) XXX_Merge(src proto.Message)

func (*Config) XXX_Size Uses

func (m *Config) XXX_Size() int

func (*Config) XXX_Unmarshal Uses

func (m *Config) XXX_Unmarshal(b []byte) error

type ConfigFormat Uses

type ConfigFormat struct {
    Name      string
    Extension []string
    Loader    ConfigLoader
}

ConfigFormat is a configurable format of V2Ray config file.

type ConfigLoader Uses

type ConfigLoader func(input io.Reader) (*Config, error)

ConfigLoader is a utility to load V2Ray config from external source.

type InboundHandlerConfig Uses

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 Uses

func (*InboundHandlerConfig) Descriptor() ([]byte, []int)

func (*InboundHandlerConfig) GetProxySettings Uses

func (m *InboundHandlerConfig) GetProxySettings() *serial.TypedMessage

func (*InboundHandlerConfig) GetReceiverSettings Uses

func (m *InboundHandlerConfig) GetReceiverSettings() *serial.TypedMessage

func (*InboundHandlerConfig) GetTag Uses

func (m *InboundHandlerConfig) GetTag() string

func (*InboundHandlerConfig) ProtoMessage Uses

func (*InboundHandlerConfig) ProtoMessage()

func (*InboundHandlerConfig) Reset Uses

func (m *InboundHandlerConfig) Reset()

func (*InboundHandlerConfig) String Uses

func (m *InboundHandlerConfig) String() string

func (*InboundHandlerConfig) XXX_DiscardUnknown Uses

func (m *InboundHandlerConfig) XXX_DiscardUnknown()

func (*InboundHandlerConfig) XXX_Marshal Uses

func (m *InboundHandlerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*InboundHandlerConfig) XXX_Merge Uses

func (m *InboundHandlerConfig) XXX_Merge(src proto.Message)

func (*InboundHandlerConfig) XXX_Size Uses

func (m *InboundHandlerConfig) XXX_Size() int

func (*InboundHandlerConfig) XXX_Unmarshal Uses

func (m *InboundHandlerConfig) XXX_Unmarshal(b []byte) error

type Instance Uses

type Instance struct {
    // contains filtered or unexported fields
}

Instance combines all functionalities in V2Ray.

func FromContext Uses

func FromContext(ctx context.Context) *Instance

FromContext returns an Instance from the given context, or nil if the context doesn't contain one.

func MustFromContext Uses

func MustFromContext(ctx context.Context) *Instance

MustFromContext returns an Instance from the given context, or panics if not present.

func New Uses

func New(config *Config) (*Instance, error)

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 StartInstance Uses

func StartInstance(configFormat string, configBytes []byte) (*Instance, error)

StartInstance starts a new V2Ray instance with given serialized config. By default V2Ray only support config in protobuf format, i.e., configFormat = "protobuf". Caller need to load other packages to add JSON support.

v2ray:api:stable

func (*Instance) AddFeature Uses

func (s *Instance) AddFeature(feature features.Feature) error

AddFeature registers a feature into current Instance.

func (*Instance) Close Uses

func (s *Instance) Close() error

Close shutdown the V2Ray instance.

func (*Instance) GetFeature Uses

func (s *Instance) GetFeature(featureType interface{}) features.Feature

GetFeature returns a feature of the given type, or nil if such feature is not registered.

func (*Instance) RequireFeatures Uses

func (s *Instance) RequireFeatures(callback interface{}) error

RequireFeatures registers a callback, which will be called when all dependent features are registered. The callback must be a func(). All its parameters must be features.Feature.

func (*Instance) Start Uses

func (s *Instance) Start() error

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.

v2ray:api:stable

func (*Instance) Type Uses

func (s *Instance) Type() interface{}

Type implements common.HasType.

type OutboundHandlerConfig Uses

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 Uses

func (*OutboundHandlerConfig) Descriptor() ([]byte, []int)

func (*OutboundHandlerConfig) GetComment Uses

func (m *OutboundHandlerConfig) GetComment() string

func (*OutboundHandlerConfig) GetExpire Uses

func (m *OutboundHandlerConfig) GetExpire() int64

func (*OutboundHandlerConfig) GetProxySettings Uses

func (m *OutboundHandlerConfig) GetProxySettings() *serial.TypedMessage

func (*OutboundHandlerConfig) GetSenderSettings Uses

func (m *OutboundHandlerConfig) GetSenderSettings() *serial.TypedMessage

func (*OutboundHandlerConfig) GetTag Uses

func (m *OutboundHandlerConfig) GetTag() string

func (*OutboundHandlerConfig) ProtoMessage Uses

func (*OutboundHandlerConfig) ProtoMessage()

func (*OutboundHandlerConfig) Reset Uses

func (m *OutboundHandlerConfig) Reset()

func (*OutboundHandlerConfig) String Uses

func (m *OutboundHandlerConfig) String() string

func (*OutboundHandlerConfig) XXX_DiscardUnknown Uses

func (m *OutboundHandlerConfig) XXX_DiscardUnknown()

func (*OutboundHandlerConfig) XXX_Marshal Uses

func (m *OutboundHandlerConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*OutboundHandlerConfig) XXX_Merge Uses

func (m *OutboundHandlerConfig) XXX_Merge(src proto.Message)

func (*OutboundHandlerConfig) XXX_Size Uses

func (m *OutboundHandlerConfig) XXX_Size() int

func (*OutboundHandlerConfig) XXX_Unmarshal Uses

func (m *OutboundHandlerConfig) XXX_Unmarshal(b []byte) error

type Server Uses

type Server interface {
    common.Runnable
}

Server is an instance of V2Ray. At any time, there must be at most one Server instance running.

Directories

PathSynopsis
appPackage app contains feature implementations of V2Ray.
app/commander
app/dispatcher
app/dnsPackage dns is an implementation of core.DNS feature.
app/log
app/log/command
app/policyPackage policy is an implementation of policy.Manager feature.
app/proxymanPackage proxyman defines applications for managing inbound and outbound proxies.
app/proxyman/command
app/proxyman/inbound
app/proxyman/outbound
app/reverse
app/router
app/stats
app/stats/command
commonPackage common contains common utilities that are shared among other packages.
common/bitmask
common/bufPackage buf provides a light-weight memory allocation mechanism.
common/bytespool
common/cryptoPackage crypto provides common crypto libraries for V2Ray.
common/crypto/internal
common/dicePackage dice contains common functions to generate random number.
common/errorsPackage errors is a drop-in replacement for Golang lib 'errors'.
common/errors/errorgen
common/log
common/mux
common/netPackage net is a drop-in replacement to Golang's net package, with some more functionalities.
common/peer
common/platform
common/platform/ctlcmd
common/platform/filesystem
common/protocol
common/protocol/bittorrent
common/protocol/dns
common/protocol/http
common/protocol/tls
common/protocol/tls/cert
common/protocol/udp
common/retry
common/serial
common/sessionPackage session provides functions for sessions of incoming requests.
common/signal
common/signal/done
common/signal/pubsub
common/signal/semaphore
common/stack
common/strmatcher
common/task
common/uuid
external/github.com/cheekybits/genny/genericPackage generic contains the generic marker types.
external/github.com/cloudflare/sidh/internal/isogeny
external/github.com/cloudflare/sidh/internal/utils
external/github.com/cloudflare/sidh/p503
external/github.com/cloudflare/sidh/p751
external/github.com/cloudflare/sidh/sidh
external/github.com/gorilla/websocketPackage websocket implements the WebSocket protocol defined in RFC 6455.
external/github.com/lucas-clemente/quic-go
external/github.com/lucas-clemente/quic-go/internal/ackhandler
external/github.com/lucas-clemente/quic-go/internal/congestion
external/github.com/lucas-clemente/quic-go/internal/flowcontrol
external/github.com/lucas-clemente/quic-go/internal/handshake
external/github.com/lucas-clemente/quic-go/internal/protocol
external/github.com/lucas-clemente/quic-go/internal/qerr
external/github.com/lucas-clemente/quic-go/internal/utils
external/github.com/lucas-clemente/quic-go/internal/utils/linkedlist
external/github.com/lucas-clemente/quic-go/internal/wire
external/github.com/marten-seemann/qtlsPackage tls partially implements TLS 1.2, as specified in RFC 5246.
external/github.com/refraction-networking/utlsPackage tls partially implements TLS 1.2, as specified in RFC 5246, and TLS 1.3, as specified in RFC 8446.
external/github.com/refraction-networking/utls/cpuPackage cpu implements processor feature detection used by the Go standard library.
features
features/dns
features/dns/localdns
features/inbound
features/outbound
features/policy
features/routing
features/stats
infra/conf
infra/conf/command
infra/conf/json
infra/conf/serial
infra/control
infra/control/main
infra/vprotogen
main
main/confloader
main/confloader/external
main/distro/all
main/distro/debug
main/json
main/jsonem
proxyPackage proxy contains all proxies used by V2Ray.
proxy/blackhole
proxy/dns
proxy/dokodemo
proxy/freedom
proxy/http
proxy/mtproto
proxy/shadowsocksPackage shadowsocks provides compatible functionality to Shadowsocks.
proxy/socksPackage socks provides implements of Socks protocol 4, 4a and 5.
proxy/vmessPackage vmess contains the implementation of VMess protocol and transportation.
proxy/vmess/encoding
proxy/vmess/inbound
proxy/vmess/outbound
testing/mocksPackage mocks is a generated GoMock package.
testing/servers/http
testing/servers/tcp
testing/servers/udp
transport
transport/internet
transport/internet/domainsocket
transport/internet/headers/http
transport/internet/headers/noop
transport/internet/headers/srtp
transport/internet/headers/tls
transport/internet/headers/utp
transport/internet/headers/wechat
transport/internet/headers/wireguard
transport/internet/http
transport/internet/kcpPackage kcp - A Fast and Reliable ARQ Protocol
transport/internet/quic
transport/internet/tcp
transport/internet/tls
transport/internet/udp
transport/internet/websocketPackage websocket implements Websocket transport
transport/pipe

Package core imports 24 packages (graph) and is imported by 66 packages. Updated 2019-08-20. Refresh now. Tools for package owners.