mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
Merge pull request #1019 from v2ray/domainsocket
Implemented Primitive Domain Socket Support described in https://github.com/v2ray/Planning/issues/25
This commit is contained in:
commit
61d9b04ca5
@ -2,6 +2,4 @@ package commander
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Commander")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Commander") }
|
||||
|
@ -2,6 +2,4 @@ package dispatcher
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Dispatcher")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Dispatcher") }
|
||||
|
@ -2,6 +2,4 @@ package command
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Proxyman", "Command")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Proxyman", "Command") }
|
||||
|
@ -6,6 +6,8 @@ import math "math"
|
||||
import v2ray_core_common_net "v2ray.com/core/common/net"
|
||||
import v2ray_core_common_net1 "v2ray.com/core/common/net"
|
||||
import v2ray_core_transport_internet "v2ray.com/core/transport/internet"
|
||||
import v2ray_core_internet_domainsocket "v2ray.com/core/transport/internet/domainsocket"
|
||||
import v2ray_core_common_serial "v2ray.com/core/common/serial"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
@ -210,13 +212,77 @@ func (m *ReceiverConfig) GetDomainOverride() []KnownProtocols {
|
||||
return nil
|
||||
}
|
||||
|
||||
type UnixReceiverConfig struct {
|
||||
DomainSockSettings *v2ray_core_internet_domainsocket.DomainSocketSettings `protobuf:"bytes,2,opt,name=domainSockSettings" json:"domainSockSettings,omitempty"`
|
||||
StreamSettings *v2ray_core_transport_internet.StreamConfig `protobuf:"bytes,4,opt,name=stream_settings,json=streamSettings" json:"stream_settings,omitempty"`
|
||||
DomainOverride []KnownProtocols `protobuf:"varint,7,rep,packed,name=domain_override,json=domainOverride,enum=v2ray.core.app.proxyman.KnownProtocols" json:"domain_override,omitempty"`
|
||||
}
|
||||
|
||||
func (m *UnixReceiverConfig) Reset() { *m = UnixReceiverConfig{} }
|
||||
func (m *UnixReceiverConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*UnixReceiverConfig) ProtoMessage() {}
|
||||
func (*UnixReceiverConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
|
||||
func (m *UnixReceiverConfig) GetDomainSockSettings() *v2ray_core_internet_domainsocket.DomainSocketSettings {
|
||||
if m != nil {
|
||||
return m.DomainSockSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UnixReceiverConfig) GetStreamSettings() *v2ray_core_transport_internet.StreamConfig {
|
||||
if m != nil {
|
||||
return m.StreamSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UnixReceiverConfig) GetDomainOverride() []KnownProtocols {
|
||||
if m != nil {
|
||||
return m.DomainOverride
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type InboundHandlerConfig struct {
|
||||
Tag string `protobuf:"bytes,1,opt,name=tag" json:"tag,omitempty"`
|
||||
ReceiverSettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,2,opt,name=receiver_settings,json=receiverSettings" json:"receiver_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_common_serial.TypedMessage `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
}
|
||||
|
||||
func (m *InboundHandlerConfig) Reset() { *m = InboundHandlerConfig{} }
|
||||
func (m *InboundHandlerConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*InboundHandlerConfig) ProtoMessage() {}
|
||||
func (*InboundHandlerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
|
||||
func (m *InboundHandlerConfig) GetTag() string {
|
||||
if m != nil {
|
||||
return m.Tag
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *InboundHandlerConfig) GetReceiverSettings() *v2ray_core_common_serial.TypedMessage {
|
||||
if m != nil {
|
||||
return m.ReceiverSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *InboundHandlerConfig) GetProxySettings() *v2ray_core_common_serial.TypedMessage {
|
||||
if m != nil {
|
||||
return m.ProxySettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type OutboundConfig struct {
|
||||
}
|
||||
|
||||
func (m *OutboundConfig) Reset() { *m = OutboundConfig{} }
|
||||
func (m *OutboundConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*OutboundConfig) ProtoMessage() {}
|
||||
func (*OutboundConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
func (*OutboundConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||
|
||||
type SenderConfig struct {
|
||||
// Send traffic through the given IP. Only IP is allowed.
|
||||
@ -229,7 +295,7 @@ type SenderConfig struct {
|
||||
func (m *SenderConfig) Reset() { *m = SenderConfig{} }
|
||||
func (m *SenderConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*SenderConfig) ProtoMessage() {}
|
||||
func (*SenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
func (*SenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||
|
||||
func (m *SenderConfig) GetVia() *v2ray_core_common_net.IPOrDomain {
|
||||
if m != nil {
|
||||
@ -259,6 +325,46 @@ func (m *SenderConfig) GetMultiplexSettings() *MultiplexingConfig {
|
||||
return nil
|
||||
}
|
||||
|
||||
type UnixSenderConfig struct {
|
||||
DomainSockSettings *v2ray_core_internet_domainsocket.DomainSocketSettings `protobuf:"bytes,1,opt,name=domainSockSettings" json:"domainSockSettings,omitempty"`
|
||||
StreamSettings *v2ray_core_transport_internet.StreamConfig `protobuf:"bytes,2,opt,name=stream_settings,json=streamSettings" json:"stream_settings,omitempty"`
|
||||
ProxySettings *v2ray_core_transport_internet.ProxyConfig `protobuf:"bytes,3,opt,name=proxy_settings,json=proxySettings" json:"proxy_settings,omitempty"`
|
||||
MultiplexSettings *MultiplexingConfig `protobuf:"bytes,4,opt,name=multiplex_settings,json=multiplexSettings" json:"multiplex_settings,omitempty"`
|
||||
}
|
||||
|
||||
func (m *UnixSenderConfig) Reset() { *m = UnixSenderConfig{} }
|
||||
func (m *UnixSenderConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*UnixSenderConfig) ProtoMessage() {}
|
||||
func (*UnixSenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
|
||||
|
||||
func (m *UnixSenderConfig) GetDomainSockSettings() *v2ray_core_internet_domainsocket.DomainSocketSettings {
|
||||
if m != nil {
|
||||
return m.DomainSockSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UnixSenderConfig) GetStreamSettings() *v2ray_core_transport_internet.StreamConfig {
|
||||
if m != nil {
|
||||
return m.StreamSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UnixSenderConfig) GetProxySettings() *v2ray_core_transport_internet.ProxyConfig {
|
||||
if m != nil {
|
||||
return m.ProxySettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UnixSenderConfig) GetMultiplexSettings() *MultiplexingConfig {
|
||||
if m != nil {
|
||||
return m.MultiplexSettings
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type MultiplexingConfig struct {
|
||||
// Whether or not Mux is enabled.
|
||||
Enabled bool `protobuf:"varint,1,opt,name=enabled" json:"enabled,omitempty"`
|
||||
@ -269,7 +375,7 @@ type MultiplexingConfig struct {
|
||||
func (m *MultiplexingConfig) Reset() { *m = MultiplexingConfig{} }
|
||||
func (m *MultiplexingConfig) String() string { return proto.CompactTextString(m) }
|
||||
func (*MultiplexingConfig) ProtoMessage() {}
|
||||
func (*MultiplexingConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||
func (*MultiplexingConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
|
||||
|
||||
func (m *MultiplexingConfig) GetEnabled() bool {
|
||||
if m != nil {
|
||||
@ -291,8 +397,11 @@ func init() {
|
||||
proto.RegisterType((*AllocationStrategy_AllocationStrategyConcurrency)(nil), "v2ray.core.app.proxyman.AllocationStrategy.AllocationStrategyConcurrency")
|
||||
proto.RegisterType((*AllocationStrategy_AllocationStrategyRefresh)(nil), "v2ray.core.app.proxyman.AllocationStrategy.AllocationStrategyRefresh")
|
||||
proto.RegisterType((*ReceiverConfig)(nil), "v2ray.core.app.proxyman.ReceiverConfig")
|
||||
proto.RegisterType((*UnixReceiverConfig)(nil), "v2ray.core.app.proxyman.UnixReceiverConfig")
|
||||
proto.RegisterType((*InboundHandlerConfig)(nil), "v2ray.core.app.proxyman.InboundHandlerConfig")
|
||||
proto.RegisterType((*OutboundConfig)(nil), "v2ray.core.app.proxyman.OutboundConfig")
|
||||
proto.RegisterType((*SenderConfig)(nil), "v2ray.core.app.proxyman.SenderConfig")
|
||||
proto.RegisterType((*UnixSenderConfig)(nil), "v2ray.core.app.proxyman.UnixSenderConfig")
|
||||
proto.RegisterType((*MultiplexingConfig)(nil), "v2ray.core.app.proxyman.MultiplexingConfig")
|
||||
proto.RegisterEnum("v2ray.core.app.proxyman.KnownProtocols", KnownProtocols_name, KnownProtocols_value)
|
||||
proto.RegisterEnum("v2ray.core.app.proxyman.AllocationStrategy_Type", AllocationStrategy_Type_name, AllocationStrategy_Type_value)
|
||||
@ -301,49 +410,60 @@ func init() {
|
||||
func init() { proto.RegisterFile("v2ray.com/core/app/proxyman/config.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 691 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x94, 0x5d, 0x6f, 0xd3, 0x3a,
|
||||
0x1c, 0xc6, 0x97, 0xb6, 0x6b, 0x7b, 0xfe, 0x5b, 0xb3, 0x1c, 0x9f, 0x23, 0x2d, 0xa7, 0x07, 0xa4,
|
||||
0x52, 0x90, 0x56, 0x0d, 0x94, 0x40, 0x27, 0x2e, 0xb8, 0x82, 0xd1, 0x4d, 0x62, 0xbc, 0xa8, 0xc1,
|
||||
0xad, 0xb8, 0x98, 0x90, 0x22, 0x2f, 0xf1, 0x8a, 0x45, 0x62, 0x47, 0x8e, 0xdb, 0x2d, 0x5f, 0x89,
|
||||
0x4f, 0xc1, 0x25, 0x9f, 0x81, 0x4f, 0x83, 0xf2, 0xd6, 0x75, 0xeb, 0x3a, 0x98, 0x76, 0xe7, 0xa6,
|
||||
0xcf, 0xf3, 0xb3, 0xfd, 0x3c, 0xb6, 0xa1, 0x37, 0xeb, 0x4b, 0x92, 0x58, 0x9e, 0x08, 0x6d, 0x4f,
|
||||
0x48, 0x6a, 0x93, 0x28, 0xb2, 0x23, 0x29, 0xce, 0x93, 0x90, 0x70, 0xdb, 0x13, 0xfc, 0x94, 0x4d,
|
||||
0xac, 0x48, 0x0a, 0x25, 0xd0, 0x76, 0xa9, 0x94, 0xd4, 0x22, 0x51, 0x64, 0x95, 0xaa, 0xf6, 0xce,
|
||||
0x15, 0x84, 0x27, 0xc2, 0x50, 0x70, 0x9b, 0x53, 0x65, 0x13, 0xdf, 0x97, 0x34, 0x8e, 0x73, 0x42,
|
||||
0xfb, 0xd1, 0x6a, 0x61, 0x24, 0xa4, 0x2a, 0x54, 0xd6, 0x15, 0x95, 0x92, 0x84, 0xc7, 0xe9, 0xff,
|
||||
0x36, 0xe3, 0x8a, 0xca, 0x54, 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||||
0x06, 0x00, 0x00,
|
||||
// 866 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x56, 0xdd, 0x6e, 0x1b, 0x45,
|
||||
0x14, 0xee, 0x7a, 0x1d, 0xdb, 0x3d, 0x69, 0x9c, 0xed, 0x50, 0xa9, 0xc6, 0x80, 0x64, 0x0c, 0xa2,
|
||||
0x56, 0x41, 0xeb, 0xe2, 0x0a, 0x24, 0xc4, 0x05, 0x84, 0xa4, 0x52, 0x13, 0x88, 0x62, 0xc6, 0x86,
|
||||
0x8b, 0x0a, 0xc9, 0x9a, 0xec, 0x4e, 0xcc, 0x28, 0xbb, 0x33, 0xab, 0x99, 0xb1, 0x9b, 0x7d, 0x25,
|
||||
0x9e, 0x81, 0x0b, 0x2e, 0xb9, 0xe0, 0x09, 0x78, 0x19, 0xd0, 0xee, 0xcc, 0x6e, 0xfc, 0xdb, 0x12,
|
||||
0x55, 0xe1, 0xa6, 0x77, 0xb3, 0xf6, 0xf7, 0x7d, 0x73, 0xce, 0x77, 0x7e, 0x34, 0xd0, 0x9b, 0x0f,
|
||||
0x24, 0x49, 0xfd, 0x40, 0xc4, 0xfd, 0x40, 0x48, 0xda, 0x27, 0x49, 0xd2, 0x4f, 0xa4, 0xb8, 0x4a,
|
||||
0x63, 0xc2, 0xfb, 0x81, 0xe0, 0x17, 0x6c, 0xea, 0x27, 0x52, 0x68, 0x81, 0x1e, 0x16, 0x48, 0x49,
|
||||
0x7d, 0x92, 0x24, 0x7e, 0x81, 0x6a, 0x3f, 0x5a, 0x91, 0x08, 0x44, 0x1c, 0x0b, 0xde, 0xe7, 0x54,
|
||||
0xf7, 0x49, 0x18, 0x4a, 0xaa, 0x94, 0x51, 0x68, 0x7f, 0xbc, 0x1d, 0x98, 0x08, 0xa9, 0x2d, 0xca,
|
||||
0x5f, 0x41, 0x69, 0x49, 0xb8, 0xca, 0xfe, 0xef, 0x33, 0xae, 0xa9, 0xcc, 0xd0, 0x8b, 0x71, 0xb5,
|
||||
0xbf, 0x7e, 0x3d, 0x3e, 0x14, 0x31, 0x61, 0x5c, 0x89, 0xe0, 0x72, 0x95, 0xfc, 0x64, 0x73, 0x48,
|
||||
0x8a, 0x4a, 0x46, 0xa2, 0xbe, 0x4e, 0x13, 0x1a, 0x4e, 0x62, 0xaa, 0x14, 0x99, 0x52, 0xc3, 0xe8,
|
||||
0xee, 0xc3, 0xde, 0x31, 0x3f, 0x17, 0x33, 0x1e, 0x1e, 0xe6, 0x42, 0xdd, 0x3f, 0x5c, 0x40, 0x07,
|
||||
0x51, 0x24, 0x02, 0xa2, 0x99, 0xe0, 0x23, 0x2d, 0x89, 0xa6, 0xd3, 0x14, 0x1d, 0x41, 0x35, 0xa3,
|
||||
0xb7, 0x9c, 0x8e, 0xd3, 0x6b, 0x0e, 0x9e, 0xf8, 0x5b, 0xdc, 0xf3, 0xd7, 0xa9, 0xfe, 0x38, 0x4d,
|
||||
0x28, 0xce, 0xd9, 0xe8, 0x12, 0x76, 0x03, 0xc1, 0x83, 0x99, 0x94, 0x94, 0x07, 0x69, 0xab, 0xd2,
|
||||
0x71, 0x7a, 0xbb, 0x83, 0xe3, 0x9b, 0x88, 0xad, 0xff, 0x74, 0x78, 0x2d, 0x88, 0x17, 0xd5, 0xd1,
|
||||
0x04, 0xea, 0x92, 0x5e, 0x48, 0xaa, 0x7e, 0x6d, 0xb9, 0xf9, 0x45, 0xcf, 0xde, 0xec, 0x22, 0x6c,
|
||||
0xc4, 0x70, 0xa1, 0xda, 0xfe, 0x02, 0x3e, 0x78, 0x65, 0x38, 0xe8, 0x01, 0xec, 0xcc, 0x49, 0x34,
|
||||
0x33, 0xae, 0xed, 0x61, 0xf3, 0xd1, 0xfe, 0x1c, 0xde, 0xdd, 0x2a, 0xbe, 0x99, 0xd2, 0xfd, 0x0c,
|
||||
0xaa, 0x99, 0x8b, 0x08, 0xa0, 0x76, 0x10, 0xbd, 0x24, 0xa9, 0xf2, 0xee, 0x64, 0x67, 0x4c, 0x78,
|
||||
0x28, 0x62, 0xcf, 0x41, 0xf7, 0xa0, 0xf1, 0xec, 0x2a, 0xeb, 0x0e, 0x12, 0x79, 0x95, 0xee, 0xdf,
|
||||
0x2e, 0x34, 0x31, 0x0d, 0x28, 0x9b, 0x53, 0x69, 0xaa, 0x8a, 0xbe, 0x01, 0xc8, 0x7a, 0x68, 0x22,
|
||||
0x09, 0x9f, 0x1a, 0xed, 0xdd, 0x41, 0x67, 0xd1, 0x0e, 0xd3, 0x29, 0x3e, 0xa7, 0xda, 0x1f, 0x0a,
|
||||
0xa9, 0x71, 0x86, 0xc3, 0x77, 0x93, 0xe2, 0x88, 0xbe, 0x82, 0x5a, 0xc4, 0x94, 0xa6, 0xdc, 0x16,
|
||||
0xed, 0xc3, 0x2d, 0xe4, 0xe3, 0xe1, 0x99, 0x3c, 0xca, 0xfb, 0x13, 0x5b, 0x02, 0xfa, 0x05, 0xde,
|
||||
0x21, 0x65, 0xbe, 0x13, 0x65, 0x13, 0xb6, 0x35, 0xf9, 0xf4, 0x06, 0x35, 0xc1, 0x88, 0xac, 0x37,
|
||||
0xe6, 0x18, 0xf6, 0x95, 0x96, 0x94, 0xc4, 0x13, 0x45, 0xb5, 0x66, 0x7c, 0xaa, 0x5a, 0xd5, 0x75,
|
||||
0xe5, 0x72, 0x8a, 0xfc, 0x62, 0x8a, 0xfc, 0x51, 0xce, 0x32, 0xfe, 0xe0, 0xa6, 0xd1, 0x18, 0x59,
|
||||
0x09, 0xf4, 0x2d, 0xbc, 0x2f, 0x8d, 0x83, 0x13, 0x21, 0xd9, 0x94, 0x71, 0x12, 0x4d, 0x42, 0xaa,
|
||||
0x34, 0xe3, 0xf9, 0xed, 0xad, 0x9d, 0x8e, 0xd3, 0x6b, 0xe0, 0xb6, 0xc5, 0x9c, 0x59, 0xc8, 0xd1,
|
||||
0x35, 0x02, 0x0d, 0x61, 0xdf, 0xcc, 0xe9, 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00,
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ option java_multiple_files = true;
|
||||
import "v2ray.com/core/common/net/address.proto";
|
||||
import "v2ray.com/core/common/net/port.proto";
|
||||
import "v2ray.com/core/transport/internet/config.proto";
|
||||
import "v2ray.com/core/transport/internet/domainsocket/config.proto";
|
||||
import "v2ray.com/core/common/serial/typed_message.proto";
|
||||
|
||||
message InboundConfig {
|
||||
}
|
||||
@ -60,8 +62,23 @@ message ReceiverConfig {
|
||||
repeated KnownProtocols domain_override = 7;
|
||||
}
|
||||
|
||||
message UnixReceiverConfig {
|
||||
reserved 1;
|
||||
v2ray.core.internet.domainsocket.DomainSocketSettings domainSockSettings = 2;
|
||||
reserved 3;
|
||||
v2ray.core.transport.internet.StreamConfig stream_settings = 4;
|
||||
reserved 5,6;
|
||||
repeated KnownProtocols domain_override = 7;
|
||||
}
|
||||
|
||||
message InboundHandlerConfig {
|
||||
string tag = 1;
|
||||
v2ray.core.common.serial.TypedMessage receiver_settings = 2;
|
||||
v2ray.core.common.serial.TypedMessage proxy_settings = 3;
|
||||
}
|
||||
|
||||
message OutboundConfig {
|
||||
|
||||
|
||||
}
|
||||
|
||||
message SenderConfig {
|
||||
@ -72,6 +89,14 @@ message SenderConfig {
|
||||
MultiplexingConfig multiplex_settings = 4;
|
||||
}
|
||||
|
||||
|
||||
message UnixSenderConfig {
|
||||
v2ray.core.internet.domainsocket.DomainSocketSettings domainSockSettings = 1;
|
||||
v2ray.core.transport.internet.StreamConfig stream_settings = 2;
|
||||
v2ray.core.transport.internet.ProxyConfig proxy_settings = 3;
|
||||
MultiplexingConfig multiplex_settings = 4;
|
||||
}
|
||||
|
||||
message MultiplexingConfig {
|
||||
// Whether or not Mux is enabled.
|
||||
bool enabled = 1;
|
||||
|
@ -2,6 +2,4 @@ package proxyman
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Proxyman")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Proxyman") }
|
||||
|
@ -2,6 +2,4 @@ package inbound
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Proxyman", "Inbound")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Proxyman", "Inbound") }
|
||||
|
@ -126,15 +126,21 @@ func NewHandler(ctx context.Context, config *core.InboundHandlerConfig) (core.In
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
receiverSettings, ok := rawReceiverSettings.(*proxyman.ReceiverConfig)
|
||||
if !ok {
|
||||
return nil, newError("not a ReceiverConfig").AtError()
|
||||
}
|
||||
proxySettings, err := config.ProxySettings.GetInstance()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tag := config.Tag
|
||||
|
||||
receiverSettings, ok := rawReceiverSettings.(*proxyman.ReceiverConfig)
|
||||
if !ok {
|
||||
receiverSettings, ok := rawReceiverSettings.(*proxyman.UnixReceiverConfig)
|
||||
if ok {
|
||||
return NewUnixInboundHandler(ctx, tag, receiverSettings, proxySettings)
|
||||
}
|
||||
return nil, newError("not a ReceiverConfig").AtError()
|
||||
}
|
||||
|
||||
allocStrategy := receiverSettings.AllocationStrategy
|
||||
if allocStrategy == nil || allocStrategy.Type == proxyman.AllocationStrategy_Always {
|
||||
return NewAlwaysOnInboundHandler(ctx, tag, receiverSettings, proxySettings)
|
||||
|
100
app/proxyman/inbound/unix.go
Normal file
100
app/proxyman/inbound/unix.go
Normal file
@ -0,0 +1,100 @@
|
||||
package inbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/proxyman/mux"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet/domainsocket"
|
||||
)
|
||||
|
||||
type UnixInboundHandler struct {
|
||||
tag string
|
||||
listenerHolder *domainsocket.Listener
|
||||
ctx context.Context
|
||||
path string
|
||||
proxy proxy.Inbound
|
||||
mux *mux.Server
|
||||
additional *proxyman.UnixReceiverConfig
|
||||
}
|
||||
|
||||
func (uih *UnixInboundHandler) Start() error {
|
||||
var err error
|
||||
uih.listenerHolder, err = domainsocket.ListenDS(uih.ctx, uih.path)
|
||||
if err != nil {
|
||||
return newError(err).AtError()
|
||||
}
|
||||
err = uih.listenerHolder.LowerUP()
|
||||
if err != nil {
|
||||
return newError(err).AtError()
|
||||
}
|
||||
nchan := make(chan net.Conn, 2)
|
||||
err = uih.listenerHolder.UP(nchan, false)
|
||||
if err != nil {
|
||||
return newError(err).AtError()
|
||||
}
|
||||
go uih.progressTraffic(nchan)
|
||||
return nil
|
||||
}
|
||||
func (uih *UnixInboundHandler) progressTraffic(rece <-chan net.Conn) {
|
||||
|
||||
for {
|
||||
conn, notclosed := <-rece
|
||||
if !notclosed {
|
||||
return
|
||||
}
|
||||
go func(conn net.Conn) {
|
||||
ctx, cancel := context.WithCancel(uih.ctx)
|
||||
if len(uih.tag) > 0 {
|
||||
ctx = proxy.ContextWithInboundTag(ctx, uih.tag)
|
||||
}
|
||||
if err := uih.proxy.Process(ctx, net.Network_TCP, conn, uih.mux); err != nil {
|
||||
newError("connection ends").Base(err).WriteToLog()
|
||||
}
|
||||
cancel()
|
||||
conn.Close()
|
||||
}(conn)
|
||||
}
|
||||
}
|
||||
func (uih *UnixInboundHandler) Close() error {
|
||||
if uih.listenerHolder != nil {
|
||||
uih.listenerHolder.Down()
|
||||
return nil
|
||||
}
|
||||
return newError("Called UnixInboundHandler.Close while listenerHolder is nil")
|
||||
|
||||
}
|
||||
func (uih *UnixInboundHandler) Tag() string {
|
||||
return uih.tag
|
||||
}
|
||||
|
||||
func (uih *UnixInboundHandler) GetRandomInboundProxy() (interface{}, net.Port, int) {
|
||||
//It makes bo sense to support it
|
||||
return nil, 0, 0
|
||||
}
|
||||
|
||||
func NewUnixInboundHandler(ctx context.Context, tag string, receiverConfig *proxyman.UnixReceiverConfig, proxyConfig interface{}) (*UnixInboundHandler, error) {
|
||||
rawProxy, err := common.CreateObject(ctx, proxyConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, ok := rawProxy.(proxy.Inbound)
|
||||
if !ok {
|
||||
return nil, newError("not an inbound proxy.")
|
||||
}
|
||||
|
||||
h := &UnixInboundHandler{
|
||||
proxy: p,
|
||||
mux: mux.NewServer(ctx),
|
||||
tag: tag,
|
||||
ctx: ctx,
|
||||
path: receiverConfig.DomainSockSettings.GetPath(),
|
||||
additional: receiverConfig,
|
||||
}
|
||||
|
||||
return h, nil
|
||||
|
||||
}
|
@ -2,6 +2,4 @@ package mux
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Proxyman", "Mux")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Proxyman", "Mux") }
|
||||
|
@ -2,6 +2,4 @@ package outbound
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("App", "Proxyman", "Outbound")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("App", "Proxyman", "Outbound") }
|
||||
|
@ -21,7 +21,7 @@ type Handler struct {
|
||||
mux *mux.ClientManager
|
||||
}
|
||||
|
||||
func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (*Handler, error) {
|
||||
func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (core.OutboundHandler, error) {
|
||||
v := core.MustFromContext(ctx)
|
||||
h := &Handler{
|
||||
config: config,
|
||||
@ -36,6 +36,8 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (*Handl
|
||||
switch s := senderSettings.(type) {
|
||||
case *proxyman.SenderConfig:
|
||||
h.senderSettings = s
|
||||
case *proxyman.UnixSenderConfig:
|
||||
return NewUnixHandler(ctx, config)
|
||||
default:
|
||||
return nil, newError("settings is not SenderConfig")
|
||||
}
|
||||
|
132
app/proxyman/outbound/unix.go
Normal file
132
app/proxyman/outbound/unix.go
Normal file
@ -0,0 +1,132 @@
|
||||
package outbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/app/proxyman/mux"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/errors"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/proxy"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/domainsocket"
|
||||
"v2ray.com/core/transport/ray"
|
||||
)
|
||||
|
||||
type UnixHandler struct {
|
||||
config *core.OutboundHandlerConfig
|
||||
senderSettings *proxyman.UnixSenderConfig
|
||||
proxy proxy.Outbound
|
||||
outboundManager core.OutboundHandlerManager
|
||||
mux *mux.ClientManager
|
||||
}
|
||||
|
||||
func NewUnixHandler(ctx context.Context, config *core.OutboundHandlerConfig) (core.OutboundHandler, error) {
|
||||
v := core.FromContext(ctx)
|
||||
if v == nil {
|
||||
return nil, newError("V is not in context")
|
||||
}
|
||||
h := &UnixHandler{
|
||||
config: config,
|
||||
outboundManager: v.OutboundHandlerManager(),
|
||||
}
|
||||
|
||||
if config.SenderSettings != nil {
|
||||
senderSettings, err := config.SenderSettings.GetInstance()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch s := senderSettings.(type) {
|
||||
case *proxyman.UnixSenderConfig:
|
||||
h.senderSettings = s
|
||||
default:
|
||||
return nil, newError("settings is not UnixSenderConfig")
|
||||
}
|
||||
}
|
||||
|
||||
proxyConfig, err := config.ProxySettings.GetInstance()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rawProxyHandler, err := common.CreateObject(ctx, proxyConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxyHandler, ok := rawProxyHandler.(proxy.Outbound)
|
||||
if !ok {
|
||||
return nil, newError("not an outbound handler")
|
||||
}
|
||||
|
||||
if h.senderSettings != nil && h.senderSettings.MultiplexSettings != nil && h.senderSettings.MultiplexSettings.Enabled {
|
||||
config := h.senderSettings.MultiplexSettings
|
||||
if config.Concurrency < 1 || config.Concurrency > 1024 {
|
||||
return nil, newError("invalid mux concurrency: ", config.Concurrency).AtWarning()
|
||||
}
|
||||
h.mux = mux.NewClientManager(proxyHandler, h, config)
|
||||
}
|
||||
|
||||
h.proxy = proxyHandler
|
||||
return h, nil
|
||||
}
|
||||
|
||||
// Tag implements core.OutboundHandler.
|
||||
func (h *UnixHandler) Tag() string {
|
||||
return h.config.Tag
|
||||
}
|
||||
|
||||
// Dispatch implements proxy.Outbound.Dispatch.
|
||||
func (h *UnixHandler) Dispatch(ctx context.Context, outboundRay ray.OutboundRay) {
|
||||
if h.mux != nil {
|
||||
err := h.mux.Dispatch(ctx, outboundRay)
|
||||
if err != nil {
|
||||
newError("failed to process outbound traffic").Base(err).WriteToLog()
|
||||
outboundRay.OutboundOutput().CloseError()
|
||||
}
|
||||
} else {
|
||||
err := h.proxy.Process(ctx, outboundRay, h)
|
||||
// Ensure outbound ray is properly closed.
|
||||
if err != nil && errors.Cause(err) != io.EOF {
|
||||
newError("failed to process outbound traffic").Base(err).WriteToLog()
|
||||
outboundRay.OutboundOutput().CloseError()
|
||||
} else {
|
||||
outboundRay.OutboundOutput().Close()
|
||||
}
|
||||
outboundRay.OutboundInput().CloseError()
|
||||
}
|
||||
}
|
||||
|
||||
// Dial implements proxy.Dialer.Dial().
|
||||
func (h *UnixHandler) Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
if h.senderSettings != nil {
|
||||
if h.senderSettings.ProxySettings.HasTag() {
|
||||
newError("Unix domain socket does not support redirect").AtWarning().WriteToLog()
|
||||
}
|
||||
|
||||
if h.senderSettings.StreamSettings != nil {
|
||||
newError("Unix domain socket does not support stream setting").AtWarning().WriteToLog()
|
||||
}
|
||||
}
|
||||
|
||||
return domainsocket.DialDS(ctx, h.senderSettings.GetDomainSockSettings().GetPath())
|
||||
}
|
||||
|
||||
// GetOutbound implements proxy.GetOutbound.
|
||||
func (h *UnixHandler) GetOutbound() proxy.Outbound {
|
||||
return h.proxy
|
||||
}
|
||||
|
||||
// Start implements common.Runnable.
|
||||
func (h *UnixHandler) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close implements common.Runnable.
|
||||
func (h *UnixHandler) Close() error {
|
||||
common.Close(h.mux)
|
||||
return nil
|
||||
}
|
@ -2,122 +2,124 @@ package internal
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
|
||||
var x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
|
||||
for i := 0; i < rounds; i += 2 {
|
||||
var x uint32
|
||||
|
||||
x0 += x4
|
||||
x = x12 ^ x0
|
||||
x12 = (x << 16) | (x >> (32 - 16))
|
||||
x8 += x12
|
||||
x = x4 ^ x8
|
||||
x4 = (x << 12) | (x >> (32 - 12))
|
||||
x0 += x4
|
||||
x = x12 ^ x0
|
||||
x12 = (x << 8) | (x >> (32 - 8))
|
||||
x8 += x12
|
||||
x = x4 ^ x8
|
||||
x4 = (x << 7) | (x >> (32 - 7))
|
||||
x1 += x5
|
||||
x = x13 ^ x1
|
||||
x13 = (x << 16) | (x >> (32 - 16))
|
||||
x9 += x13
|
||||
x = x5 ^ x9
|
||||
x5 = (x << 12) | (x >> (32 - 12))
|
||||
x1 += x5
|
||||
x = x13 ^ x1
|
||||
x13 = (x << 8) | (x >> (32 - 8))
|
||||
x9 += x13
|
||||
x = x5 ^ x9
|
||||
x5 = (x << 7) | (x >> (32 - 7))
|
||||
x2 += x6
|
||||
x = x14 ^ x2
|
||||
x14 = (x << 16) | (x >> (32 - 16))
|
||||
x10 += x14
|
||||
x = x6 ^ x10
|
||||
x6 = (x << 12) | (x >> (32 - 12))
|
||||
x2 += x6
|
||||
x = x14 ^ x2
|
||||
x14 = (x << 8) | (x >> (32 - 8))
|
||||
x10 += x14
|
||||
x = x6 ^ x10
|
||||
x6 = (x << 7) | (x >> (32 - 7))
|
||||
x3 += x7
|
||||
x = x15 ^ x3
|
||||
x15 = (x << 16) | (x >> (32 - 16))
|
||||
x11 += x15
|
||||
x = x7 ^ x11
|
||||
x7 = (x << 12) | (x >> (32 - 12))
|
||||
x3 += x7
|
||||
x = x15 ^ x3
|
||||
x15 = (x << 8) | (x >> (32 - 8))
|
||||
x11 += x15
|
||||
x = x7 ^ x11
|
||||
x7 = (x << 7) | (x >> (32 - 7))
|
||||
x0 += x5
|
||||
x = x15 ^ x0
|
||||
x15 = (x << 16) | (x >> (32 - 16))
|
||||
x10 += x15
|
||||
x = x5 ^ x10
|
||||
x5 = (x << 12) | (x >> (32 - 12))
|
||||
x0 += x5
|
||||
x = x15 ^ x0
|
||||
x15 = (x << 8) | (x >> (32 - 8))
|
||||
x10 += x15
|
||||
x = x5 ^ x10
|
||||
x5 = (x << 7) | (x >> (32 - 7))
|
||||
x1 += x6
|
||||
x = x12 ^ x1
|
||||
x12 = (x << 16) | (x >> (32 - 16))
|
||||
x11 += x12
|
||||
x = x6 ^ x11
|
||||
x6 = (x << 12) | (x >> (32 - 12))
|
||||
x1 += x6
|
||||
x = x12 ^ x1
|
||||
x12 = (x << 8) | (x >> (32 - 8))
|
||||
x11 += x12
|
||||
x = x6 ^ x11
|
||||
x6 = (x << 7) | (x >> (32 - 7))
|
||||
x2 += x7
|
||||
x = x13 ^ x2
|
||||
x13 = (x << 16) | (x >> (32 - 16))
|
||||
x8 += x13
|
||||
x = x7 ^ x8
|
||||
x7 = (x << 12) | (x >> (32 - 12))
|
||||
x2 += x7
|
||||
x = x13 ^ x2
|
||||
x13 = (x << 8) | (x >> (32 - 8))
|
||||
x8 += x13
|
||||
x = x7 ^ x8
|
||||
x7 = (x << 7) | (x >> (32 - 7))
|
||||
x3 += x4
|
||||
x = x14 ^ x3
|
||||
x14 = (x << 16) | (x >> (32 - 16))
|
||||
x9 += x14
|
||||
x = x4 ^ x9
|
||||
x4 = (x << 12) | (x >> (32 - 12))
|
||||
x3 += x4
|
||||
x = x14 ^ x3
|
||||
x14 = (x << 8) | (x >> (32 - 8))
|
||||
x9 += x14
|
||||
x = x4 ^ x9
|
||||
x4 = (x << 7) | (x >> (32 - 7))
|
||||
}
|
||||
binary.LittleEndian.PutUint32(out[0:4], s[0]+x0)
|
||||
binary.LittleEndian.PutUint32(out[4:8], s[1]+x1)
|
||||
binary.LittleEndian.PutUint32(out[8:12], s[2]+x2)
|
||||
binary.LittleEndian.PutUint32(out[12:16], s[3]+x3)
|
||||
binary.LittleEndian.PutUint32(out[16:20], s[4]+x4)
|
||||
binary.LittleEndian.PutUint32(out[20:24], s[5]+x5)
|
||||
binary.LittleEndian.PutUint32(out[24:28], s[6]+x6)
|
||||
binary.LittleEndian.PutUint32(out[28:32], s[7]+x7)
|
||||
binary.LittleEndian.PutUint32(out[32:36], s[8]+x8)
|
||||
binary.LittleEndian.PutUint32(out[36:40], s[9]+x9)
|
||||
binary.LittleEndian.PutUint32(out[40:44], s[10]+x10)
|
||||
binary.LittleEndian.PutUint32(out[44:48], s[11]+x11)
|
||||
binary.LittleEndian.PutUint32(out[48:52], s[12]+x12)
|
||||
binary.LittleEndian.PutUint32(out[52:56], s[13]+x13)
|
||||
binary.LittleEndian.PutUint32(out[56:60], s[14]+x14)
|
||||
binary.LittleEndian.PutUint32(out[60:64], s[15]+x15)
|
||||
func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
|
||||
var x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15 = s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9],s[10],s[11],s[12],s[13],s[14],s[15]
|
||||
for i := 0; i < rounds; i+=2 {
|
||||
var x uint32
|
||||
|
||||
x0+=x4
|
||||
x=x12^x0
|
||||
x12=(x << 16) | (x >> (32 - 16))
|
||||
x8+=x12
|
||||
x=x4^x8
|
||||
x4=(x << 12) | (x >> (32 - 12))
|
||||
x0+=x4
|
||||
x=x12^x0
|
||||
x12=(x << 8) | (x >> (32 - 8))
|
||||
x8+=x12
|
||||
x=x4^x8
|
||||
x4=(x << 7) | (x >> (32 - 7))
|
||||
x1+=x5
|
||||
x=x13^x1
|
||||
x13=(x << 16) | (x >> (32 - 16))
|
||||
x9+=x13
|
||||
x=x5^x9
|
||||
x5=(x << 12) | (x >> (32 - 12))
|
||||
x1+=x5
|
||||
x=x13^x1
|
||||
x13=(x << 8) | (x >> (32 - 8))
|
||||
x9+=x13
|
||||
x=x5^x9
|
||||
x5=(x << 7) | (x >> (32 - 7))
|
||||
x2+=x6
|
||||
x=x14^x2
|
||||
x14=(x << 16) | (x >> (32 - 16))
|
||||
x10+=x14
|
||||
x=x6^x10
|
||||
x6=(x << 12) | (x >> (32 - 12))
|
||||
x2+=x6
|
||||
x=x14^x2
|
||||
x14=(x << 8) | (x >> (32 - 8))
|
||||
x10+=x14
|
||||
x=x6^x10
|
||||
x6=(x << 7) | (x >> (32 - 7))
|
||||
x3+=x7
|
||||
x=x15^x3
|
||||
x15=(x << 16) | (x >> (32 - 16))
|
||||
x11+=x15
|
||||
x=x7^x11
|
||||
x7=(x << 12) | (x >> (32 - 12))
|
||||
x3+=x7
|
||||
x=x15^x3
|
||||
x15=(x << 8) | (x >> (32 - 8))
|
||||
x11+=x15
|
||||
x=x7^x11
|
||||
x7=(x << 7) | (x >> (32 - 7))
|
||||
x0+=x5
|
||||
x=x15^x0
|
||||
x15=(x << 16) | (x >> (32 - 16))
|
||||
x10+=x15
|
||||
x=x5^x10
|
||||
x5=(x << 12) | (x >> (32 - 12))
|
||||
x0+=x5
|
||||
x=x15^x0
|
||||
x15=(x << 8) | (x >> (32 - 8))
|
||||
x10+=x15
|
||||
x=x5^x10
|
||||
x5=(x << 7) | (x >> (32 - 7))
|
||||
x1+=x6
|
||||
x=x12^x1
|
||||
x12=(x << 16) | (x >> (32 - 16))
|
||||
x11+=x12
|
||||
x=x6^x11
|
||||
x6=(x << 12) | (x >> (32 - 12))
|
||||
x1+=x6
|
||||
x=x12^x1
|
||||
x12=(x << 8) | (x >> (32 - 8))
|
||||
x11+=x12
|
||||
x=x6^x11
|
||||
x6=(x << 7) | (x >> (32 - 7))
|
||||
x2+=x7
|
||||
x=x13^x2
|
||||
x13=(x << 16) | (x >> (32 - 16))
|
||||
x8+=x13
|
||||
x=x7^x8
|
||||
x7=(x << 12) | (x >> (32 - 12))
|
||||
x2+=x7
|
||||
x=x13^x2
|
||||
x13=(x << 8) | (x >> (32 - 8))
|
||||
x8+=x13
|
||||
x=x7^x8
|
||||
x7=(x << 7) | (x >> (32 - 7))
|
||||
x3+=x4
|
||||
x=x14^x3
|
||||
x14=(x << 16) | (x >> (32 - 16))
|
||||
x9+=x14
|
||||
x=x4^x9
|
||||
x4=(x << 12) | (x >> (32 - 12))
|
||||
x3+=x4
|
||||
x=x14^x3
|
||||
x14=(x << 8) | (x >> (32 - 8))
|
||||
x9+=x14
|
||||
x=x4^x9
|
||||
x4=(x << 7) | (x >> (32 - 7))
|
||||
}
|
||||
binary.LittleEndian.PutUint32(out[0:4], s[0]+x0)
|
||||
binary.LittleEndian.PutUint32(out[4:8], s[1]+x1)
|
||||
binary.LittleEndian.PutUint32(out[8:12], s[2]+x2)
|
||||
binary.LittleEndian.PutUint32(out[12:16], s[3]+x3)
|
||||
binary.LittleEndian.PutUint32(out[16:20], s[4]+x4)
|
||||
binary.LittleEndian.PutUint32(out[20:24], s[5]+x5)
|
||||
binary.LittleEndian.PutUint32(out[24:28], s[6]+x6)
|
||||
binary.LittleEndian.PutUint32(out[28:32], s[7]+x7)
|
||||
binary.LittleEndian.PutUint32(out[32:36], s[8]+x8)
|
||||
binary.LittleEndian.PutUint32(out[36:40], s[9]+x9)
|
||||
binary.LittleEndian.PutUint32(out[40:44], s[10]+x10)
|
||||
binary.LittleEndian.PutUint32(out[44:48], s[11]+x11)
|
||||
binary.LittleEndian.PutUint32(out[48:52], s[12]+x12)
|
||||
binary.LittleEndian.PutUint32(out[52:56], s[13]+x13)
|
||||
binary.LittleEndian.PutUint32(out[56:60], s[14]+x14)
|
||||
binary.LittleEndian.PutUint32(out[60:64], s[15]+x15)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,4 @@ package blackhole
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "Blackhole")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "Blackhole") }
|
||||
|
@ -2,6 +2,4 @@ package dokodemo
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "Dokodemo")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "Dokodemo") }
|
||||
|
@ -2,6 +2,4 @@ package freedom
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "Freedom")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "Freedom") }
|
||||
|
@ -2,6 +2,4 @@ package shadowsocks
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "Shadowsocks")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "Shadowsocks") }
|
||||
|
@ -2,6 +2,4 @@ package socks
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "Socks")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "Socks") }
|
||||
|
@ -2,6 +2,4 @@ package encoding
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "VMess", "Encoding")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "VMess", "Encoding") }
|
||||
|
@ -2,6 +2,4 @@ package vmess
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "VMess")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "VMess") }
|
||||
|
@ -2,6 +2,4 @@ package inbound
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "VMess", "Inbound")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "VMess", "Inbound") }
|
||||
|
@ -2,6 +2,4 @@ package outbound
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Proxy", "VMess", "Outbound")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Proxy", "VMess", "Outbound") }
|
||||
|
1
testing/scenarios/unixtest/unix.go
Normal file
1
testing/scenarios/unixtest/unix.go
Normal file
@ -0,0 +1 @@
|
||||
package unixtest
|
129
testing/scenarios/unixtest/unix_test.go
Normal file
129
testing/scenarios/unixtest/unix_test.go
Normal file
@ -0,0 +1,129 @@
|
||||
package unixtest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"v2ray.com/core"
|
||||
"v2ray.com/core/app/log"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common"
|
||||
clog "v2ray.com/core/common/log"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy/dokodemo"
|
||||
"v2ray.com/core/proxy/freedom"
|
||||
. "v2ray.com/ext/assert"
|
||||
|
||||
"v2ray.com/core/testing/servers/tcp"
|
||||
|
||||
"v2ray.com/core/testing/scenarios"
|
||||
|
||||
"v2ray.com/core/transport/internet/domainsocket"
|
||||
)
|
||||
|
||||
func xor(b []byte) []byte {
|
||||
r := make([]byte, len(b))
|
||||
for i, v := range b {
|
||||
r[i] = v ^ 'c'
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func pickPort() net.Port {
|
||||
listener, err := net.Listen("tcp4", "127.0.0.1:0")
|
||||
common.Must(err)
|
||||
defer listener.Close()
|
||||
|
||||
addr := listener.Addr().(*net.TCPAddr)
|
||||
return net.Port(addr.Port)
|
||||
}
|
||||
|
||||
func TestUnix2tcpS(t *testing.T) {
|
||||
assert := With(t)
|
||||
tcpServer := tcp.Server{
|
||||
MsgProcessor: xor,
|
||||
}
|
||||
dest, err := tcpServer.Start()
|
||||
assert(err, IsNil)
|
||||
defer tcpServer.Close()
|
||||
|
||||
Server := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&log.Config{
|
||||
ErrorLogLevel: clog.Severity_Debug,
|
||||
ErrorLogType: log.LogType_Console,
|
||||
}),
|
||||
},
|
||||
Inbound: []*core.InboundHandlerConfig{
|
||||
{
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.UnixReceiverConfig{
|
||||
DomainSockSettings: &domainsocket.DomainSocketSettings{Path: "\x00v2raytest"},
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
Outbound: []*core.OutboundHandlerConfig{
|
||||
{ProxySettings: serial.ToTypedMessage(&freedom.Config{})},
|
||||
},
|
||||
}
|
||||
serverPort := pickPort()
|
||||
Client := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(&log.Config{
|
||||
ErrorLogLevel: clog.Severity_Debug,
|
||||
ErrorLogType: log.LogType_Console,
|
||||
}),
|
||||
},
|
||||
Outbound: []*core.OutboundHandlerConfig{
|
||||
{
|
||||
SenderSettings: serial.ToTypedMessage(&proxyman.UnixSenderConfig{
|
||||
DomainSockSettings: &domainsocket.DomainSocketSettings{Path: "\x00v2raytest"},
|
||||
}),
|
||||
ProxySettings: serial.ToTypedMessage(&freedom.Config{}),
|
||||
},
|
||||
},
|
||||
Inbound: []*core.InboundHandlerConfig{
|
||||
{ProxySettings: serial.ToTypedMessage(&dokodemo.Config{
|
||||
Address: net.NewIPOrDomain(dest.Address),
|
||||
Port: uint32(dest.Port),
|
||||
NetworkList: &net.NetworkList{
|
||||
Network: []net.Network{net.Network_TCP},
|
||||
},
|
||||
}),
|
||||
ReceiverSettings: serial.ToTypedMessage(&proxyman.ReceiverConfig{
|
||||
PortRange: net.SinglePortRange(serverPort),
|
||||
Listen: net.NewIPOrDomain(net.LocalHostIP),
|
||||
}),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
servers, err := scenarios.InitializeServerConfigs(Server, Client)
|
||||
|
||||
port := serverPort
|
||||
|
||||
conn, err := net.DialTCP("tcp", nil, &net.TCPAddr{
|
||||
IP: []byte{127, 0, 0, 1},
|
||||
Port: int(port),
|
||||
})
|
||||
assert(err, IsNil)
|
||||
|
||||
payload := "dokodemo request."
|
||||
nBytes, err := conn.Write([]byte(payload))
|
||||
assert(err, IsNil)
|
||||
assert(nBytes, Equals, len(payload))
|
||||
|
||||
response := make([]byte, 1024)
|
||||
nBytes, err = conn.Read(response)
|
||||
assert(err, IsNil)
|
||||
assert(response[:nBytes], Equals, xor([]byte(payload)))
|
||||
assert(conn.Close(), IsNil)
|
||||
|
||||
scenarios.CloseAllServers(servers)
|
||||
}
|
155
transport/internet/domainsocket/config.pb.go
Normal file
155
transport/internet/domainsocket/config.pb.go
Normal file
@ -0,0 +1,155 @@
|
||||
package domainsocket
|
||||
|
||||
import proto "github.com/golang/protobuf/proto"
|
||||
import fmt "fmt"
|
||||
import math "math"
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
// Flag Array
|
||||
type DomainSocketSecurityMode int32
|
||||
|
||||
const (
|
||||
DomainSocketSecurityMode_Danger DomainSocketSecurityMode = 0
|
||||
// Verfify is Dialer have a pid or ppid match pid file
|
||||
DomainSocketSecurityMode_VerifyPid DomainSocketSecurityMode = 1
|
||||
// Do not tolerance ppid match
|
||||
DomainSocketSecurityMode_DisqualifyPPIDMatch DomainSocketSecurityMode = 2
|
||||
// Enforce Uid Verify On euid
|
||||
DomainSocketSecurityMode_VerifyEUID DomainSocketSecurityMode = 4
|
||||
// Enforce Uid Verify On ruid
|
||||
DomainSocketSecurityMode_VerifyRUID DomainSocketSecurityMode = 8
|
||||
// Does not allow same user exception
|
||||
DomainSocketSecurityMode_DisqualifySameUser DomainSocketSecurityMode = 16
|
||||
// Does not allow root user exception
|
||||
DomainSocketSecurityMode_DisqualifyRootUser DomainSocketSecurityMode = 32
|
||||
)
|
||||
|
||||
var DomainSocketSecurityMode_name = map[int32]string{
|
||||
0: "Danger",
|
||||
1: "VerifyPid",
|
||||
2: "DisqualifyPPIDMatch",
|
||||
4: "VerifyEUID",
|
||||
8: "VerifyRUID",
|
||||
16: "DisqualifySameUser",
|
||||
32: "DisqualifyRootUser",
|
||||
}
|
||||
var DomainSocketSecurityMode_value = map[string]int32{
|
||||
"Danger": 0,
|
||||
"VerifyPid": 1,
|
||||
"DisqualifyPPIDMatch": 2,
|
||||
"VerifyEUID": 4,
|
||||
"VerifyRUID": 8,
|
||||
"DisqualifySameUser": 16,
|
||||
"DisqualifyRootUser": 32,
|
||||
}
|
||||
|
||||
func (x DomainSocketSecurityMode) String() string {
|
||||
return proto.EnumName(DomainSocketSecurityMode_name, int32(x))
|
||||
}
|
||||
func (DomainSocketSecurityMode) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
|
||||
type DomainSocketSecurity struct {
|
||||
// Flag Array Type, User can set an integer to define various configure
|
||||
Mode DomainSocketSecurityMode `protobuf:"varint,1,opt,name=Mode,enum=v2ray.core.internet.domainsocket.DomainSocketSecurityMode" json:"Mode,omitempty"`
|
||||
// Set pid files to be allowed
|
||||
AllowedPid []string `protobuf:"bytes,2,rep,name=AllowedPid" json:"AllowedPid,omitempty"`
|
||||
// Set uids to be allowed, either euid or ruid should match one of following
|
||||
// uids AllowedUid, or user that v2ray is running or root.
|
||||
AllowedUid []uint64 `protobuf:"varint,3,rep,packed,name=AllowedUid" json:"AllowedUid,omitempty"`
|
||||
}
|
||||
|
||||
func (m *DomainSocketSecurity) Reset() { *m = DomainSocketSecurity{} }
|
||||
func (m *DomainSocketSecurity) String() string { return proto.CompactTextString(m) }
|
||||
func (*DomainSocketSecurity) ProtoMessage() {}
|
||||
func (*DomainSocketSecurity) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
|
||||
func (m *DomainSocketSecurity) GetMode() DomainSocketSecurityMode {
|
||||
if m != nil {
|
||||
return m.Mode
|
||||
}
|
||||
return DomainSocketSecurityMode_Danger
|
||||
}
|
||||
|
||||
func (m *DomainSocketSecurity) GetAllowedPid() []string {
|
||||
if m != nil {
|
||||
return m.AllowedPid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DomainSocketSecurity) GetAllowedUid() []uint64 {
|
||||
if m != nil {
|
||||
return m.AllowedUid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type DomainSocketSettings struct {
|
||||
// Path we should listen/dial
|
||||
Path string `protobuf:"bytes,1,opt,name=Path" json:"Path,omitempty"`
|
||||
Security *DomainSocketSecurity `protobuf:"bytes,2,opt,name=Security" json:"Security,omitempty"`
|
||||
}
|
||||
|
||||
func (m *DomainSocketSettings) Reset() { *m = DomainSocketSettings{} }
|
||||
func (m *DomainSocketSettings) String() string { return proto.CompactTextString(m) }
|
||||
func (*DomainSocketSettings) ProtoMessage() {}
|
||||
func (*DomainSocketSettings) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||
|
||||
func (m *DomainSocketSettings) GetPath() string {
|
||||
if m != nil {
|
||||
return m.Path
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *DomainSocketSettings) GetSecurity() *DomainSocketSecurity {
|
||||
if m != nil {
|
||||
return m.Security
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*DomainSocketSecurity)(nil), "v2ray.core.internet.domainsocket.DomainSocketSecurity")
|
||||
proto.RegisterType((*DomainSocketSettings)(nil), "v2ray.core.internet.domainsocket.DomainSocketSettings")
|
||||
proto.RegisterEnum("v2ray.core.internet.domainsocket.DomainSocketSecurityMode", DomainSocketSecurityMode_name, DomainSocketSecurityMode_value)
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterFile("v2ray.com/core/transport/internet/domainsocket/config.proto", fileDescriptor0)
|
||||
}
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 323 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x41, 0x4b, 0xf3, 0x40,
|
||||
0x10, 0x86, 0xbf, 0xb4, 0xa1, 0xb4, 0xf3, 0x69, 0x09, 0xab, 0x68, 0x4e, 0x12, 0x7a, 0x0a, 0x1e,
|
||||
0x12, 0xa8, 0xe0, 0x41, 0x4f, 0x4a, 0x3c, 0xf4, 0x50, 0x09, 0x5b, 0xea, 0xc1, 0xdb, 0x9a, 0xdd,
|
||||
0xb6, 0x8b, 0xed, 0x4e, 0xdd, 0x4c, 0x95, 0x5e, 0xfc, 0x29, 0x1e, 0xfd, 0x9d, 0xd2, 0x95, 0xd8,
|
||||
0x28, 0x8a, 0xe0, 0x2d, 0xf3, 0xe4, 0x9d, 0x87, 0x77, 0x60, 0xe1, 0xfc, 0xb1, 0x6f, 0xc5, 0x3a,
|
||||
0x29, 0x70, 0x91, 0x16, 0x68, 0x55, 0x4a, 0x56, 0x98, 0x72, 0x89, 0x96, 0x52, 0x6d, 0x48, 0x59,
|
||||
0xa3, 0x28, 0x95, 0xb8, 0x10, 0xda, 0x94, 0x58, 0xdc, 0x2b, 0x4a, 0x0b, 0x34, 0x13, 0x3d, 0x4d,
|
||||
0x96, 0x16, 0x09, 0x59, 0x54, 0x2d, 0x5b, 0x95, 0x54, 0xf1, 0xa4, 0x1e, 0xef, 0xbd, 0x7a, 0xb0,
|
||||
0x9f, 0x39, 0x30, 0x72, 0x60, 0xa4, 0x8a, 0x95, 0xd5, 0xb4, 0x66, 0xd7, 0xe0, 0x0f, 0x51, 0xaa,
|
||||
0xd0, 0x8b, 0xbc, 0xb8, 0xdb, 0x3f, 0x4b, 0x7e, 0x33, 0x25, 0xdf, 0x59, 0x36, 0x06, 0xee, 0x3c,
|
||||
0xec, 0x08, 0xe0, 0x62, 0x3e, 0xc7, 0x27, 0x25, 0x73, 0x2d, 0xc3, 0x46, 0xd4, 0x8c, 0x3b, 0xbc,
|
||||
0x46, 0x6a, 0xff, 0xc7, 0x5a, 0x86, 0xcd, 0xa8, 0x19, 0xfb, 0xbc, 0x46, 0x7a, 0xcf, 0x5f, 0x7b,
|
||||
0x12, 0x69, 0x33, 0x2d, 0x19, 0x03, 0x3f, 0x17, 0x34, 0x73, 0x3d, 0x3b, 0xdc, 0x7d, 0x33, 0x0e,
|
||||
0xed, 0xaa, 0x41, 0xd8, 0x88, 0xbc, 0xf8, 0x7f, 0xff, 0xf4, 0x6f, 0xfd, 0xf9, 0x87, 0xe7, 0xf8,
|
||||
0xc5, 0x83, 0xf0, 0xa7, 0x13, 0x19, 0x40, 0x2b, 0x13, 0x66, 0xaa, 0x6c, 0xf0, 0x8f, 0xed, 0x42,
|
||||
0xe7, 0x46, 0x59, 0x3d, 0x59, 0xe7, 0x5a, 0x06, 0x1e, 0x3b, 0x84, 0xbd, 0x4c, 0x97, 0x0f, 0x2b,
|
||||
0x31, 0xdf, 0xa0, 0x7c, 0x90, 0x0d, 0x05, 0x15, 0xb3, 0xa0, 0xc1, 0xba, 0x00, 0xef, 0xb9, 0xab,
|
||||
0xf1, 0x20, 0x0b, 0xfc, 0xed, 0xcc, 0x37, 0x73, 0x9b, 0x1d, 0x00, 0xdb, 0x2e, 0x8e, 0xc4, 0x42,
|
||||
0x8d, 0x4b, 0x65, 0x83, 0xe0, 0x33, 0xe7, 0x88, 0xe4, 0x78, 0x74, 0xd9, 0xbd, 0xdd, 0xa9, 0xdf,
|
||||
0x73, 0xd7, 0x72, 0x4f, 0xe0, 0xe4, 0x2d, 0x00, 0x00, 0xff, 0xff, 0x30, 0xd5, 0x61, 0x90, 0x41,
|
||||
0x02, 0x00, 0x00,
|
||||
}
|
42
transport/internet/domainsocket/config.proto
Normal file
42
transport/internet/domainsocket/config.proto
Normal file
@ -0,0 +1,42 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package v2ray.core.internet.domainsocket;
|
||||
|
||||
option go_package = "domainsocket";
|
||||
|
||||
//Flag Array
|
||||
enum DomainSocketSecurityMode {
|
||||
Danger = 0;
|
||||
//Verfify is Dialer have a pid or ppid match pid file
|
||||
VerifyPid = 1;
|
||||
//Do not tolerance ppid match
|
||||
DisqualifyPPIDMatch = 2;
|
||||
|
||||
//Enforce Uid Verify On euid
|
||||
VerifyEUID = 4;
|
||||
|
||||
//Enforce Uid Verify On ruid
|
||||
VerifyRUID = 8;
|
||||
|
||||
//Does not allow same user exception
|
||||
DisqualifySameUser = 16;
|
||||
|
||||
//Does not allow root user exception
|
||||
DisqualifyRootUser = 32;
|
||||
}
|
||||
|
||||
message DomainSocketSecurity{
|
||||
//Flag Array Type, User can set an integer to define various configure
|
||||
DomainSocketSecurityMode Mode = 1;
|
||||
//Set pid files to be allowed
|
||||
repeated string AllowedPid = 2;
|
||||
//Set uids to be allowed, either euid or ruid should match one of following
|
||||
//uids AllowedUid, or user that v2ray is running or root.
|
||||
repeated uint64 AllowedUid = 3;
|
||||
}
|
||||
|
||||
message DomainSocketSettings{
|
||||
//Path we should listen/dial
|
||||
string Path = 1;
|
||||
DomainSocketSecurity Security = 2;
|
||||
}
|
18
transport/internet/domainsocket/dial.go
Normal file
18
transport/internet/domainsocket/dial.go
Normal file
@ -0,0 +1,18 @@
|
||||
package domainsocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
)
|
||||
|
||||
func DialDS(ctx context.Context, path string) (*net.UnixConn, error) {
|
||||
resolvedAddress, err := net.ResolveUnixAddr("unix", path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dialedUnix, err := net.DialUnix("unix", nil, resolvedAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dialedUnix, nil
|
||||
}
|
3
transport/internet/domainsocket/errgen.go
Normal file
3
transport/internet/domainsocket/errgen.go
Normal file
@ -0,0 +1,3 @@
|
||||
package domainsocket
|
||||
|
||||
//go:generate go run $GOPATH/src/v2ray.com/core/common/errors/errorgen/main.go -pkg domainsocket -path Transport,Internet,DomainSocket
|
5
transport/internet/domainsocket/errors.generated.go
Normal file
5
transport/internet/domainsocket/errors.generated.go
Normal file
@ -0,0 +1,5 @@
|
||||
package domainsocket
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "DomainSocket") }
|
217
transport/internet/domainsocket/listener.go
Normal file
217
transport/internet/domainsocket/listener.go
Normal file
@ -0,0 +1,217 @@
|
||||
package domainsocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/common/bitmask"
|
||||
)
|
||||
|
||||
type Listener struct {
|
||||
ln net.Listener
|
||||
listenerChan chan<- net.Conn
|
||||
ctx context.Context
|
||||
path string
|
||||
lockfile *os.File
|
||||
state bitmask.Byte
|
||||
cancal func()
|
||||
}
|
||||
|
||||
const (
|
||||
STATE_UNDEFINED = 0
|
||||
STATE_INITIALIZED = 1 << iota
|
||||
STATE_LOWERUP = 1 << iota
|
||||
STATE_UP = 1 << iota
|
||||
STATE_TAINT = 1 << iota
|
||||
)
|
||||
|
||||
func ListenDS(ctx context.Context, path string) (*Listener, error) {
|
||||
|
||||
vln := &Listener{path: path, state: STATE_INITIALIZED, ctx: ctx}
|
||||
return vln, nil
|
||||
}
|
||||
|
||||
func (ls *Listener) Down() error {
|
||||
var err error
|
||||
if !ls.state.Has(STATE_LOWERUP | STATE_UP) {
|
||||
err = newError(ls.state).Base(newError("Invalid State:Down"))
|
||||
if ___DEBUG_PANIC_WHEN_ENCOUNTED_IMPOSSIBLE_ERROR {
|
||||
panic(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
ls.cancal()
|
||||
closeerr := ls.ln.Close()
|
||||
var lockerr error
|
||||
if isUnixDomainSocketFileSystemBased(ls.path) {
|
||||
lockerr = giveupLock(ls.lockfile)
|
||||
}
|
||||
if closeerr != nil && lockerr != nil {
|
||||
if ___DEBUG_PANIC_WHEN_ERROR_UNPROPAGATEABLE {
|
||||
panic(closeerr.Error() + lockerr.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if closeerr != nil {
|
||||
return newError("Cannot Close Unix domain socket listener").Base(closeerr)
|
||||
}
|
||||
if lockerr != nil {
|
||||
return newError("Cannot release lock for Unix domain socket listener").Base(lockerr)
|
||||
}
|
||||
ls.state.Clear(STATE_LOWERUP | STATE_UP)
|
||||
return nil
|
||||
}
|
||||
|
||||
//LowerUP Setup systen level Listener
|
||||
func (ls *Listener) LowerUP() error {
|
||||
var err error
|
||||
|
||||
if !ls.state.Has(STATE_INITIALIZED) || ls.state.Has(STATE_LOWERUP) {
|
||||
err = newError(ls.state).Base(newError("Invalid State:LowerUP"))
|
||||
if ___DEBUG_PANIC_WHEN_ENCOUNTED_IMPOSSIBLE_ERROR {
|
||||
panic(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
//If the unix domain socket is filesystem based, an file lock must be used to claim the right for listening on respective file.
|
||||
//https://gavv.github.io/blog/unix-socket-reuse/
|
||||
if isUnixDomainSocketFileSystemBased(ls.path) && !___DEBUG_IGNORE_FLOCK {
|
||||
ls.lockfile, err = acquireLock(ls.path + ".lock")
|
||||
if err != nil {
|
||||
newError(err).AtDebug().WriteToLog()
|
||||
return newError("Unable to acquire lock for filesystem based unix domain socket").Base(err)
|
||||
}
|
||||
|
||||
err = cleansePath(ls.path)
|
||||
if err != nil {
|
||||
return newError("Unable to cleanse path for the creation of unix domain socket").Base(err)
|
||||
}
|
||||
}
|
||||
|
||||
addr := new(net.UnixAddr)
|
||||
addr.Name = ls.path
|
||||
addr.Net = "unix"
|
||||
li, err := net.ListenUnix("unix", addr)
|
||||
ls.ln = li
|
||||
if err != nil {
|
||||
return newError("Unable to listen unix domain socket").Base(err)
|
||||
}
|
||||
|
||||
ls.state.Set(STATE_LOWERUP)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ls *Listener) UP(listener chan<- net.Conn, allowkick bool) error {
|
||||
var err error
|
||||
if !ls.state.Has(STATE_INITIALIZED|STATE_LOWERUP) || (ls.state.Has(STATE_UP) && !allowkick) {
|
||||
err = newError(ls.state).Base(newError("Invalid State:UP"))
|
||||
if ___DEBUG_PANIC_WHEN_ENCOUNTED_IMPOSSIBLE_ERROR {
|
||||
panic(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
ls.listenerChan = listener
|
||||
if !ls.state.Has(STATE_UP) {
|
||||
cctx, cancel := context.WithCancel(ls.ctx)
|
||||
ls.cancal = cancel
|
||||
go ls.uploop(cctx)
|
||||
}
|
||||
ls.state.Set(STATE_UP)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ls *Listener) uploop(cctx context.Context) {
|
||||
var lasterror error
|
||||
errortolerance := 5
|
||||
for {
|
||||
if cctx.Err() != nil {
|
||||
close(ls.listenerChan)
|
||||
return
|
||||
}
|
||||
conn, err := ls.ln.Accept()
|
||||
|
||||
if err != nil {
|
||||
newError("Cannot Accept socket from listener").Base(err).AtDebug().WriteToLog()
|
||||
//Guard against too many open file error
|
||||
if err == lasterror {
|
||||
errortolerance--
|
||||
if errortolerance == 0 {
|
||||
newError("unix domain socket melt down as the error is repeating").Base(err).AtError().WriteToLog()
|
||||
ls.cancal()
|
||||
}
|
||||
newError("unix domain socket listener is throttling accept as the error is repeating").Base(err).AtError().WriteToLog()
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
lasterror = err
|
||||
}
|
||||
|
||||
ls.listenerChan <- conn
|
||||
}
|
||||
}
|
||||
|
||||
func isUnixDomainSocketFileSystemBased(path string) bool {
|
||||
//No Branching
|
||||
return path[0] != 0
|
||||
}
|
||||
|
||||
func acquireLock(lockfilepath string) (*os.File, error) {
|
||||
f, err := os.Create(lockfilepath)
|
||||
if err != nil {
|
||||
newError(err).AtDebug().WriteToLog()
|
||||
return f, err
|
||||
}
|
||||
err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX)
|
||||
if err != nil {
|
||||
newError(err).AtDebug().WriteToLog()
|
||||
err = f.Close()
|
||||
if err != nil {
|
||||
if ___DEBUG_PANIC_WHEN_ENCOUNTED_IMPOSSIBLE_ERROR {
|
||||
panic(err)
|
||||
}
|
||||
newError(err).AtDebug().WriteToLog()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func giveupLock(locker *os.File) error {
|
||||
err := syscall.Flock(int(locker.Fd()), syscall.LOCK_UN)
|
||||
if err != nil {
|
||||
closeerr := locker.Close()
|
||||
if err != nil {
|
||||
if ___DEBUG_PANIC_WHEN_ERROR_UNPROPAGATEABLE {
|
||||
panic(closeerr)
|
||||
}
|
||||
newError(closeerr).AtDebug().WriteToLog()
|
||||
}
|
||||
newError(err).AtDebug().WriteToLog()
|
||||
return err
|
||||
}
|
||||
closeerr := locker.Close()
|
||||
if closeerr != nil {
|
||||
newError(closeerr).AtDebug().WriteToLog()
|
||||
return closeerr
|
||||
}
|
||||
return closeerr
|
||||
}
|
||||
|
||||
func cleansePath(path string) error {
|
||||
_, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
err = os.Remove(path)
|
||||
return err
|
||||
}
|
||||
|
||||
//DEBUG CONSTS
|
||||
const ___DEBUG_IGNORE_FLOCK = false
|
||||
const ___DEBUG_PANIC_WHEN_ERROR_UNPROPAGATEABLE = false
|
||||
const ___DEBUG_PANIC_WHEN_ENCOUNTED_IMPOSSIBLE_ERROR = false
|
132
transport/internet/domainsocket/listener_test.go
Normal file
132
transport/internet/domainsocket/listener_test.go
Normal file
@ -0,0 +1,132 @@
|
||||
package domainsocket_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/transport/internet/domainsocket"
|
||||
"v2ray.com/ext/assert"
|
||||
)
|
||||
|
||||
func TestListenAbstract(t *testing.T) {
|
||||
listener, err := domainsocket.ListenDS(context.Background(), "\x00V2RayDimension/TestListenAbstract")
|
||||
asrt := assert.With(t)
|
||||
asrt(err, assert.IsNil)
|
||||
asrt(listener, assert.IsNotNil)
|
||||
}
|
||||
|
||||
func TestListen(t *testing.T) {
|
||||
listener, err := domainsocket.ListenDS(context.Background(), "/tmp/ts3")
|
||||
asrt := assert.With(t)
|
||||
asrt(err, assert.IsNil)
|
||||
asrt(listener, assert.IsNotNil)
|
||||
errolu := listener.LowerUP()
|
||||
asrt(errolu, assert.IsNil)
|
||||
ctx, fin := context.WithCancel(context.Background())
|
||||
chi := make(chan net.Conn, 2)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case conn := <-chi:
|
||||
test := make([]byte, 256)
|
||||
nc, errc := conn.Read(test)
|
||||
asrt(errc, assert.IsNil)
|
||||
conn.Write(test[:nc])
|
||||
time.Sleep(time.Second)
|
||||
conn.Close()
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
listener.UP(chi, false)
|
||||
con, erro := net.Dial("unix", "/tmp/ts3")
|
||||
asrt(erro, assert.IsNil)
|
||||
b := []byte("ABC")
|
||||
c := []byte("XXX")
|
||||
_, erron := con.Write(b)
|
||||
asrt(erron, assert.IsNil)
|
||||
con.Read(c)
|
||||
con.Close()
|
||||
asrt(b[0]-c[0] == 0, assert.IsTrue)
|
||||
fin()
|
||||
listener.Down()
|
||||
}
|
||||
|
||||
func TestListenA(t *testing.T) {
|
||||
listener, err := domainsocket.ListenDS(context.Background(), "\x00/tmp/ts2")
|
||||
asrt := assert.With(t)
|
||||
asrt(err, assert.IsNil)
|
||||
asrt(listener, assert.IsNotNil)
|
||||
errolu := listener.LowerUP()
|
||||
asrt(errolu, assert.IsNil)
|
||||
ctx, fin := context.WithCancel(context.Background())
|
||||
chi := make(chan net.Conn, 2)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case conn := <-chi:
|
||||
test := make([]byte, 256)
|
||||
nc, errc := conn.Read(test)
|
||||
asrt(errc, assert.IsNil)
|
||||
conn.Write(test[:nc])
|
||||
time.Sleep(time.Second)
|
||||
conn.Close()
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
listener.UP(chi, false)
|
||||
con, erro := net.Dial("unix", "\x00/tmp/ts2")
|
||||
asrt(erro, assert.IsNil)
|
||||
b := []byte("ABC")
|
||||
c := []byte("XXX")
|
||||
_, erron := con.Write(b)
|
||||
asrt(erron, assert.IsNil)
|
||||
con.Read(c)
|
||||
con.Close()
|
||||
asrt(b[0]-c[0] == 0, assert.IsTrue)
|
||||
fin()
|
||||
listener.Down()
|
||||
}
|
||||
|
||||
func TestListenDial(t *testing.T) {
|
||||
listener, err := domainsocket.ListenDS(context.Background(), "\x00/tmp/ts")
|
||||
asrt := assert.With(t)
|
||||
asrt(err, assert.IsNil)
|
||||
asrt(listener, assert.IsNotNil)
|
||||
errolu := listener.LowerUP()
|
||||
asrt(errolu, assert.IsNil)
|
||||
ctx, fin := context.WithCancel(context.Background())
|
||||
chi := make(chan net.Conn, 2)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case conn := <-chi:
|
||||
test := make([]byte, 256)
|
||||
nc, errc := conn.Read(test)
|
||||
asrt(errc, assert.IsNil)
|
||||
conn.Write(test[:nc])
|
||||
time.Sleep(time.Second)
|
||||
conn.Close()
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
listener.UP(chi, false)
|
||||
con, erro := domainsocket.DialDS(context.Background(), "\x00/tmp/ts")
|
||||
asrt(erro, assert.IsNil)
|
||||
b := []byte("ABC")
|
||||
c := []byte("XXX")
|
||||
_, erron := con.Write(b)
|
||||
asrt(erron, assert.IsNil)
|
||||
con.Read(c)
|
||||
con.Close()
|
||||
asrt(b[0]-c[0] == 0, assert.IsTrue)
|
||||
fin()
|
||||
listener.Down()
|
||||
}
|
@ -2,6 +2,4 @@ package internet
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet") }
|
||||
|
@ -2,6 +2,4 @@ package http
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet", "Headers", "HTTP")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "Headers", "HTTP") }
|
||||
|
@ -2,6 +2,4 @@ package kcp
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet", "mKCP")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "mKCP") }
|
||||
|
@ -2,6 +2,4 @@ package tcp
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet", "TCP")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "TCP") }
|
||||
|
@ -2,6 +2,4 @@ package tls
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet", "TLS")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "TLS") }
|
||||
|
@ -2,6 +2,4 @@ package udp
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet", "UDP")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "UDP") }
|
||||
|
@ -2,6 +2,4 @@ package websocket
|
||||
|
||||
import "v2ray.com/core/common/errors"
|
||||
|
||||
func newError(values ...interface{}) *errors.Error {
|
||||
return errors.New(values...).Path("Transport", "Internet", "WebSocket")
|
||||
}
|
||||
func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("Transport", "Internet", "WebSocket") }
|
||||
|
Loading…
Reference in New Issue
Block a user