core

package module
v4.0.0-...-960decf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2022 License: AGPL-3.0 Imports: 28 Imported by: 0

README

Warning This project is no longer being maintained. Use https://github.com/database64128/shadowsocks-go instead.

v2ray-go

An opinionated fork of v2fly/v2ray-core.

Additional Features

No. Description Commit Author
1. 📅 Add flag -suppressTimestamps to suppress timestamps in logs. 7c9f1f86727541e0e996733841773e54bce8b296 @database64128
2. 🔌 Refine systemd unit files 09c9cd81347730557de50df100611c81043a449d @database64128
3. 🍥 DNS query strategy: Add UseIPFailFast: This strategy enables both IPv4 and IPv6. When either A or AAAA query fails, the lookup operation is deemed a failure. Fixes v2fly/v2ray-core#1209. ddfb88eea5534730417c7c62c27ed932c3645306 @database64128
4. 📦 Release packages: Use proper GOOS-GOARCH naming instead of the confusing "friendly" names. 989cc06ebeb79c172836cadc325bd037b909b165 @database64128
5. 🚮 Removed browser forwarder's securedload. 8d9d576a2ca5fc152c453d9ceaa2f7dc0e559f83 @moodyhunter
6. 🚮 Removed legacy MTProto v1. 7894e4b46c10785bf29ff5ae47991769bdd32410 @moodyhunter
7. 🚮 Removed deprecated inboundDetour and outboundDetour 25ac8395e697ffad50ff735ca49487a3198bc096 @moodyhunter
8. 🚮 Removed useless VLESS aba0348410ebe7c3165b2f2f24377a2fe08cca32 @moodyhunter
9. ⚡️ Performance: Enable ReadV by default 0fcfd1ed94fe194fd5acb5553090a1f97de966f4 @AkinoKaede
10. 🚮 VMess: Drop vnext and VMess MD5 (with alterId). To migrate your JSON config, just move what's previously in vnext up one level. d99fa66e116612b3f834073671178b4b4e390a65, e7bc3878aed6ad861dea5f05b19053af88e23f2b @AkinoKaede, @database64128
11. 🌐 DNS: Respect TTL in RRs 95eaaa93b80b39edb86b8b69d03e1fe3e3932aea @rurirei
12. 👀 Happy Eyeballs v1 with built-in DNS and configurable fallback delay and domain strategy #12 @database64128
13. 🔧 Fix: net.ParseAddress can't handle CIDR #12 @database64128
14. 🪢 Replace sendThrough with bindInterface (interface name), bind4 (interface name or IPv4), bind6 (interface name or IPv6) #12 @database64128
15. ➕ Performance: Increase buffer size from 2K to 20K a87b0d2fc0f6b7b9051b98403f1a89e621c2e4a1 @database64128
16. ⏱️ Remove TCP idle timeout 73e50fe7441263681cc104c0831cf9fe9a299b36 @database64128
17. 👃 Add routeOnly sniffing option 2786ece5f3e96eaa177e62d7fb26be5a37ebb484 @nekohasekai
18. 🦘 Sniffer: Add SkipDomainDestinations and SkippedDomains 54893b89443136a49b46fba56bdf03f45f918f83 @database64128
19. 🦩 Refine linux TFO setsockopt 497167dfc60af447a68630cc2e25f4638ee172d2 @database64128

License

This project is licensed under AGPLv3

The upstream v2fly/v2ray-core is licensed under the MIT License.

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

This section is empty.

Variables

View Source
var File_config_proto protoreflect.FileDescriptor

Functions

func AddInboundHandler

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

func AddOutboundHandler

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

func CreateObject

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

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

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

func RegisterConfigLoader(format *ConfigFormat) error

RegisterConfigLoader add a new ConfigLoader.

func RequireFeatures

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

func ServerType() interface{}

ServerType returns the type of the server.

func ToBackgroundDetachedContext

func ToBackgroundDetachedContext(ctx context.Context) context.Context

ToBackgroundDetachedContext create a detached context from another context Internal API

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 Annotation

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

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
	//
	// Deprecated: Do not use.
	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"`
	// contains filtered or unexported fields
}

Config is the master config of V2Ray. V2Ray takes this config as input and functions accordingly.

func LoadConfig

func LoadConfig(formatName string, filename string, input interface{}) (*Config, error)

LoadConfig loads config with given format from given source. input accepts 2 different types: * []string slice of multiple filename/url(s) to open to read * io.Reader that reads a config content (the original way)

func (*Config) Descriptor deprecated

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

Deprecated: Use Config.ProtoReflect.Descriptor instead.

func (*Config) GetApp

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

func (*Config) GetExtension

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

func (*Config) GetInbound

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

func (*Config) GetOutbound

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

func (*Config) GetTransport deprecated

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

Deprecated: Do not use.

func (*Config) ProtoMessage

func (*Config) ProtoMessage()

func (*Config) ProtoReflect

func (x *Config) ProtoReflect() protoreflect.Message

func (*Config) Reset

func (x *Config) Reset()

func (*Config) String

func (x *Config) String() string

type ConfigFormat

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

ConfigFormat is a configurable format of V2Ray config file.

type ConfigLoader

type ConfigLoader func(input interface{}) (*Config, error)

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

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"`
	// contains filtered or unexported fields
}

InboundHandlerConfig is the configuration for inbound handler.

func (*InboundHandlerConfig) Descriptor deprecated

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

Deprecated: Use InboundHandlerConfig.ProtoReflect.Descriptor instead.

func (*InboundHandlerConfig) GetProxySettings

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

func (*InboundHandlerConfig) GetReceiverSettings

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

func (*InboundHandlerConfig) GetTag

func (x *InboundHandlerConfig) GetTag() string

func (*InboundHandlerConfig) ProtoMessage

func (*InboundHandlerConfig) ProtoMessage()

func (*InboundHandlerConfig) ProtoReflect

func (x *InboundHandlerConfig) ProtoReflect() protoreflect.Message

func (*InboundHandlerConfig) Reset

func (x *InboundHandlerConfig) Reset()

func (*InboundHandlerConfig) String

func (x *InboundHandlerConfig) String() string

type Instance

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

Instance combines all functionalities in V2Ray.

func FromContext

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

func MustFromContext(ctx context.Context) *Instance

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

func New

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 NewWithContext

func NewWithContext(ctx context.Context, config *Config) (*Instance, error)

func StartInstance

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

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

AddFeature registers a feature into current Instance.

func (*Instance) Close

func (s *Instance) Close() error

Close shutdown the V2Ray instance.

func (*Instance) GetFeature

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

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

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

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

Type implements common.HasType.

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"`
	// contains filtered or unexported fields
}

OutboundHandlerConfig is the configuration for outbound handler.

func (*OutboundHandlerConfig) Descriptor deprecated

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

Deprecated: Use OutboundHandlerConfig.ProtoReflect.Descriptor instead.

func (*OutboundHandlerConfig) GetComment

func (x *OutboundHandlerConfig) GetComment() string

func (*OutboundHandlerConfig) GetExpire

func (x *OutboundHandlerConfig) GetExpire() int64

func (*OutboundHandlerConfig) GetProxySettings

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

func (*OutboundHandlerConfig) GetSenderSettings

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

func (*OutboundHandlerConfig) GetTag

func (x *OutboundHandlerConfig) GetTag() string

func (*OutboundHandlerConfig) ProtoMessage

func (*OutboundHandlerConfig) ProtoMessage()

func (*OutboundHandlerConfig) ProtoReflect

func (x *OutboundHandlerConfig) ProtoReflect() protoreflect.Message

func (*OutboundHandlerConfig) Reset

func (x *OutboundHandlerConfig) Reset()

func (*OutboundHandlerConfig) String

func (x *OutboundHandlerConfig) String() string

type Server

type Server interface {
	common.Runnable
}

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

Directories

Path Synopsis
app
Package app contains feature implementations of V2Ray.
Package app contains feature implementations of V2Ray.
dns
Package dns is an implementation of core.DNS feature.
Package dns is an implementation of core.DNS feature.
log
policy
Package policy is an implementation of policy.Manager feature.
Package policy is an implementation of policy.Manager feature.
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'.
log
mux
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.
dns
infra
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.
dns
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
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL