mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
refine domain socket transport
This commit is contained in:
parent
4b45174650
commit
a320196b77
@ -6,7 +6,6 @@ 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.
|
||||
@ -157,7 +156,9 @@ func (m *AllocationStrategy_AllocationStrategyRefresh) GetValue() uint32 {
|
||||
}
|
||||
|
||||
type ReceiverConfig struct {
|
||||
PortRange *v2ray_core_common_net1.PortRange `protobuf:"bytes,1,opt,name=port_range,json=portRange" json:"port_range,omitempty"`
|
||||
// PortRange specifies the ports which the Receiver should listen on.
|
||||
PortRange *v2ray_core_common_net1.PortRange `protobuf:"bytes,1,opt,name=port_range,json=portRange" json:"port_range,omitempty"`
|
||||
// Listen specifies the IP address that the Receiver should listen on.
|
||||
Listen *v2ray_core_common_net.IPOrDomain `protobuf:"bytes,2,opt,name=listen" json:"listen,omitempty"`
|
||||
AllocationStrategy *AllocationStrategy `protobuf:"bytes,3,opt,name=allocation_strategy,json=allocationStrategy" json:"allocation_strategy,omitempty"`
|
||||
StreamSettings *v2ray_core_transport_internet.StreamConfig `protobuf:"bytes,4,opt,name=stream_settings,json=streamSettings" json:"stream_settings,omitempty"`
|
||||
@ -212,38 +213,6 @@ 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"`
|
||||
@ -253,7 +222,7 @@ type InboundHandlerConfig struct {
|
||||
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 (*InboundHandlerConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
|
||||
|
||||
func (m *InboundHandlerConfig) GetTag() string {
|
||||
if m != nil {
|
||||
@ -282,7 +251,7 @@ 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{5} }
|
||||
func (*OutboundConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
|
||||
|
||||
type SenderConfig struct {
|
||||
// Send traffic through the given IP. Only IP is allowed.
|
||||
@ -295,7 +264,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{6} }
|
||||
func (*SenderConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
|
||||
|
||||
func (m *SenderConfig) GetVia() *v2ray_core_common_net.IPOrDomain {
|
||||
if m != nil {
|
||||
@ -325,46 +294,6 @@ 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"`
|
||||
@ -375,7 +304,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{8} }
|
||||
func (*MultiplexingConfig) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
|
||||
|
||||
func (m *MultiplexingConfig) GetEnabled() bool {
|
||||
if m != nil {
|
||||
@ -397,11 +326,9 @@ 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)
|
||||
@ -410,60 +337,54 @@ func init() {
|
||||
func init() { proto.RegisterFile("v2ray.com/core/app/proxyman/config.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 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, 0x44, 0xcc, 0xa9, 0x94, 0x2c, 0xa4, 0xad, 0x7a, 0xc7,
|
||||
0xed, 0x35, 0x07, 0x8f, 0xb6, 0x66, 0xfc, 0x3d, 0x17, 0x2f, 0xf9, 0x30, 0x1b, 0xcb, 0x40, 0x44,
|
||||
0x0a, 0x37, 0x0d, 0xff, 0xcc, 0xd2, 0x4f, 0xaa, 0x8d, 0x9a, 0x57, 0xef, 0xfe, 0x5e, 0x01, 0xf4,
|
||||
0x13, 0x67, 0x57, 0x2b, 0x05, 0xbe, 0x00, 0x64, 0xe0, 0x23, 0x11, 0x5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4f, 0xad, 0xee, 0xfd, 0x52, 0xa6, 0x34, 0xf7, 0x9f,
|
||||
0x0a, 0x78, 0xd9, 0xa8, 0x2d, 0xd9, 0xb9, 0x79, 0xd0, 0x9c, 0xff, 0x63, 0xd0, 0xde, 0xbe, 0x0a,
|
||||
0x0c, 0x01, 0xad, 0x03, 0x51, 0x0b, 0xea, 0x94, 0x93, 0xf3, 0x88, 0x86, 0xb9, 0xef, 0x0d, 0x5c,
|
||||
0x7c, 0xa2, 0xce, 0xfa, 0xfb, 0x62, 0x6f, 0xe9, 0x51, 0xf0, 0xf8, 0x23, 0x68, 0x2e, 0x6f, 0x0e,
|
||||
0xd4, 0x80, 0xea, 0xf3, 0xf1, 0x78, 0xe8, 0xdd, 0x41, 0x75, 0x70, 0xc7, 0x3f, 0x8c, 0x3c, 0xe7,
|
||||
0xbb, 0x43, 0x78, 0x2f, 0x10, 0xf1, 0xb6, 0xd8, 0x87, 0xce, 0x8b, 0x46, 0x71, 0xfe, 0xad, 0xf2,
|
||||
0xf0, 0xe7, 0x01, 0x26, 0xa9, 0x7f, 0x98, 0xa1, 0x0e, 0x92, 0xc4, 0x38, 0x15, 0x13, 0x7e, 0x5e,
|
||||
0xcb, 0x1f, 0x58, 0x4f, 0xff, 0x0d, 0x00, 0x00, 0xff, 0xff, 0x97, 0xb5, 0xcf, 0xbd, 0x93, 0x0a,
|
||||
0x00, 0x00,
|
||||
// 772 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x95, 0x5f, 0x6f, 0xeb, 0x34,
|
||||
0x18, 0xc6, 0x4f, 0x9a, 0x9e, 0xb6, 0xe7, 0xdd, 0x69, 0x96, 0x63, 0x26, 0xad, 0x14, 0x90, 0x4a,
|
||||
0x41, 0xac, 0x1a, 0x28, 0x19, 0x9d, 0xb8, 0xe0, 0x0a, 0x46, 0x37, 0x69, 0x03, 0xa6, 0x06, 0xb7,
|
||||
0xe2, 0x62, 0x42, 0x8a, 0xbc, 0xc4, 0x0b, 0x11, 0x89, 0x1d, 0x39, 0x6e, 0xb7, 0x7c, 0x25, 0x3e,
|
||||
0x05, 0x97, 0x5c, 0xf0, 0x09, 0xf8, 0x34, 0x28, 0x71, 0xd2, 0x3f, 0x6b, 0x3b, 0xce, 0xb4, 0x3b,
|
||||
0x67, 0x7b, 0x9e, 0x9f, 0xed, 0xe7, 0x7d, 0xfd, 0x16, 0x06, 0xf3, 0xa1, 0x20, 0x99, 0xe5, 0xf1,
|
||||
0xd8, 0xf6, 0xb8, 0xa0, 0x36, 0x49, 0x12, 0x3b, 0x11, 0xfc, 0x21, 0x8b, 0x09, 0xb3, 0x3d, 0xce,
|
||||
0xee, 0xc2, 0xc0, 0x4a, 0x04, 0x97, 0x1c, 0x1d, 0x56, 0x4a, 0x41, 0x2d, 0x92, 0x24, 0x56, 0xa5,
|
||||
0xea, 0x1e, 0x3d, 0x42, 0x78, 0x3c, 0x8e, 0x39, 0xb3, 0x19, 0x95, 0x36, 0xf1, 0x7d, 0x41, 0xd3,
|
||||
0x54, 0x11, 0xba, 0x9f, 0xef, 0x16, 0x26, 0x5c, 0xc8, 0x52, 0x65, 0x3d, 0x52, 0x49, 0x41, 0x58,
|
||||
0x9a, 0xff, 0xdf, 0x0e, 0x99, 0xa4, 0x22, 0x57, 0xaf, 0x9e, 0xab, 0x7b, 0xb2, 0x9d, 0x9a, 0x52,
|
||||
0x11, 0x92, 0xc8, 0x96, 0x59, 0x42, 0x7d, 0x37, 0xa6, 0x69, 0x4a, 0x02, 0xaa, 0x1c, 0xfd, 0x7d,
|
||||
0x68, 0x5f, 0xb1, 0x5b, 0x3e, 0x63, 0xfe, 0xa8, 0x00, 0xf5, 0xff, 0xd2, 0x01, 0x9d, 0x45, 0x11,
|
||||
0xf7, 0x88, 0x0c, 0x39, 0x9b, 0x48, 0x41, 0x24, 0x0d, 0x32, 0x74, 0x0e, 0xf5, 0xdc, 0xde, 0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1a, 0xe5, 0xaa, 0xb3, 0x24, 0x51, 0x49, 0xc5, 0x84,
|
||||
0xdd, 0x36, 0x8a, 0xdf, 0xa7, 0xd3, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x6a, 0xe5, 0x6f, 0xed,
|
||||
0x95, 0x07, 0x00, 0x00,
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ 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 {
|
||||
@ -53,7 +52,9 @@ enum KnownProtocols {
|
||||
}
|
||||
|
||||
message ReceiverConfig {
|
||||
// PortRange specifies the ports which the Receiver should listen on.
|
||||
v2ray.core.common.net.PortRange port_range = 1;
|
||||
// Listen specifies the IP address that the Receiver should listen on.
|
||||
v2ray.core.common.net.IPOrDomain listen = 2;
|
||||
AllocationStrategy allocation_strategy = 3;
|
||||
v2ray.core.transport.internet.StreamConfig stream_settings = 4;
|
||||
@ -62,15 +63,6 @@ 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;
|
||||
@ -89,14 +81,6 @@ 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;
|
||||
|
@ -134,10 +134,6 @@ func NewHandler(ctx context.Context, config *core.InboundHandlerConfig) (core.In
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
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
|
||||
|
||||
}
|
@ -36,8 +36,6 @@ func NewHandler(ctx context.Context, config *core.OutboundHandlerConfig) (core.O
|
||||
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")
|
||||
}
|
||||
|
@ -1,132 +0,0 @@
|
||||
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
|
||||
}
|
@ -5,8 +5,7 @@ import fmt "fmt"
|
||||
import math "math"
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
|
@ -10,6 +10,7 @@ var DialUnix = net.DialUnix
|
||||
var Listen = net.Listen
|
||||
var ListenTCP = net.ListenTCP
|
||||
var ListenUDP = net.ListenUDP
|
||||
var ListenUnix = net.ListenUnix
|
||||
|
||||
var LookupIP = net.LookupIP
|
||||
|
||||
@ -48,3 +49,5 @@ type Dialer = net.Dialer
|
||||
type Listener = net.Listener
|
||||
type TCPListener = net.TCPListener
|
||||
type UnixListener = net.UnixListener
|
||||
|
||||
var ResolveUnixAddr = net.ResolveUnixAddr
|
||||
|
@ -1 +0,0 @@
|
||||
package unixtest
|
@ -1,129 +0,0 @@
|
||||
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)
|
||||
}
|
@ -19,11 +19,12 @@ const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
type TransportProtocol int32
|
||||
|
||||
const (
|
||||
TransportProtocol_TCP TransportProtocol = 0
|
||||
TransportProtocol_UDP TransportProtocol = 1
|
||||
TransportProtocol_MKCP TransportProtocol = 2
|
||||
TransportProtocol_WebSocket TransportProtocol = 3
|
||||
TransportProtocol_HTTP TransportProtocol = 4
|
||||
TransportProtocol_TCP TransportProtocol = 0
|
||||
TransportProtocol_UDP TransportProtocol = 1
|
||||
TransportProtocol_MKCP TransportProtocol = 2
|
||||
TransportProtocol_WebSocket TransportProtocol = 3
|
||||
TransportProtocol_HTTP TransportProtocol = 4
|
||||
TransportProtocol_DomainSocket TransportProtocol = 5
|
||||
)
|
||||
|
||||
var TransportProtocol_name = map[int32]string{
|
||||
@ -32,13 +33,15 @@ var TransportProtocol_name = map[int32]string{
|
||||
2: "MKCP",
|
||||
3: "WebSocket",
|
||||
4: "HTTP",
|
||||
5: "DomainSocket",
|
||||
}
|
||||
var TransportProtocol_value = map[string]int32{
|
||||
"TCP": 0,
|
||||
"UDP": 1,
|
||||
"MKCP": 2,
|
||||
"WebSocket": 3,
|
||||
"HTTP": 4,
|
||||
"TCP": 0,
|
||||
"UDP": 1,
|
||||
"MKCP": 2,
|
||||
"WebSocket": 3,
|
||||
"HTTP": 4,
|
||||
"DomainSocket": 5,
|
||||
}
|
||||
|
||||
func (x TransportProtocol) String() string {
|
||||
@ -141,29 +144,30 @@ func init() {
|
||||
func init() { proto.RegisterFile("v2ray.com/core/transport/internet/config.proto", fileDescriptor0) }
|
||||
|
||||
var fileDescriptor0 = []byte{
|
||||
// 379 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0x4f, 0x4b, 0xf3, 0x40,
|
||||
0x10, 0x87, 0xdf, 0x24, 0xe5, 0x35, 0x9d, 0xb6, 0x9a, 0xee,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xd5, 0x57, 0x23, 0x03, 0x00, 0x00,
|
||||
// 393 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xcf, 0x6a, 0xdb, 0x40,
|
||||
0x10, 0x87, 0x2b, 0xc9, 0x6d, 0xe5, 0xb1, 0xdd, 0xae, 0xf7, 0x64, 0x0a, 0xa6, 0xae, 0x0b, 0x45,
|
||||
0xf4, 0xb0, 0x32, 0xea, 0x1b, 0x58, 0x3e, 0xb4, 0xb4, 0xa6, 0x42, 0x52, 0x5b, 0x30, 0x14, 0xb3,
|
||||
0xde, 0x6c, 0x84, 0x88, 0xa5, 0x35, 0xab, 0x4d, 0x88, 0x9e, 0x27, 0xb7, 0xdc, 0xf3, 0x7e, 0x41,
|
||||
0xff, 0x16, 0x93, 0x80, 0xf1, 0x25, 0xb7, 0x41, 0xf3, 0x9b, 0x6f, 0x3e, 0xcd, 0x02, 0xb9, 0xf1,
|
||||
0x24, 0x2d, 0x09, 0x13, 0x99, 0xcb, 0x84, 0xe4, 0xae, 0x92, 0x34, 0x2f, 0x0e, 0x42, 0x2a, 0x37,
|
||||
0xcd, 0x15, 0x97, 0x39, 0x57, 0x2e, 0x13, 0xf9, 0x65, 0x9a, 0x90, 0x83, 0x14, 0x4a, 0xe0, 0x69,
|
||||
0x97, 0x97, 0x9c, 0xe8, 0x2c, 0xe9, 0xb2, 0x1f, 0x16, 0x4f, 0x70, 0x4c, 0x64, 0x99, 0xc8, 0xdd,
|
||||
0x82, 0xcb, 0x94, 0xee, 0x5d, 0x55, 0x1e, 0xf8, 0xc5, 0x36, 0xe3, 0x45, 0x41, 0x13, 0xde, 0x00,
|
||||
0xe7, 0x77, 0x06, 0xbc, 0x8f, 0x3b, 0x90, 0x5f, 0xaf, 0xc2, 0xbf, 0xc0, 0xae, 0x9b, 0x4c, 0xec,
|
||||
0x27, 0xc6, 0xcc, 0x70, 0xde, 0x79, 0x0b, 0x72, 0x72, 0x2f, 0xd1, 0x84, 0xa0, 0x9d, 0x0b, 0x35,
|
||||
0x01, 0x2f, 0xc1, 0x2e, 0xb8, 0x52, 0x69, 0x9e, 0x14, 0x13, 0x73, 0x66, 0x38, 0x03, 0xef, 0xcb,
|
||||
0x31, 0xad, 0x51, 0x24, 0x8d, 0x22, 0x89, 0x2b, 0xc5, 0x75, 0x63, 0x18, 0xea, 0xb9, 0xf9, 0x83,
|
||||
0x09, 0xc3, 0x48, 0x49, 0x4e, 0xb3, 0x17, 0x51, 0xfc, 0x0f, 0x58, 0x4f, 0x6c, 0x8f, 0x64, 0x2d,
|
||||
0x67, 0xe0, 0x91, 0x73, 0xb9, 0x8d, 0x59, 0x38, 0xd6, 0x99, 0xa8, 0x05, 0xe1, 0xcf, 0x30, 0x2a,
|
||||
0x38, 0xbb, 0x96, 0xa9, 0x2a, 0xb7, 0xd5, 0x1b, 0x4c, 0xac, 0x99, 0xe1, 0xf4, 0xc3, 0x61, 0xf7,
|
||||
0xb1, 0xfa, 0x69, 0x1c, 0xc1, 0x58, 0x87, 0xb4, 0x42, 0xaf, 0x56, 0x38, 0xf7, 0x5e, 0xa8, 0x03,
|
||||
0x74, 0x9b, 0xe7, 0x1f, 0x61, 0x10, 0x48, 0x71, 0x5b, 0xb6, 0x57, 0x43, 0x60, 0x29, 0x9a, 0xd4,
|
||||
0x07, 0xeb, 0x87, 0x55, 0xf9, 0x75, 0x03, 0xe3, 0x67, 0x87, 0xc1, 0x6f, 0xc1, 0x8a, 0xfd, 0x00,
|
||||
0xbd, 0xaa, 0x8a, 0x3f, 0xab, 0x00, 0x19, 0xd8, 0x86, 0xde, 0xfa, 0xa7, 0x1f, 0x20, 0x13, 0x8f,
|
||||
0xa0, 0xff, 0x8f, 0xef, 0x22, 0xc1, 0xae, 0xb8, 0x42, 0x56, 0xd5, 0xf8, 0x1e, 0xc7, 0x01, 0xea,
|
||||
0x61, 0x04, 0xc3, 0x95, 0xc8, 0x68, 0x9a, 0xb7, 0xbd, 0xd7, 0xcb, 0xdf, 0xf0, 0x89, 0x89, 0xec,
|
||||
0xf4, 0xf9, 0x02, 0x63, 0x63, 0x77, 0xf5, 0xbd, 0x39, 0xfd, 0xeb, 0x85, 0xb4, 0x24, 0x7e, 0x95,
|
||||
0xd5, 0x5a, 0xe4, 0x47, 0xdb, 0xdf, 0xbd, 0xa9, 0x1f, 0xec, 0xdb, 0x63, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0xa2, 0xdf, 0xde, 0xa4, 0x35, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ enum TransportProtocol {
|
||||
MKCP = 2;
|
||||
WebSocket = 3;
|
||||
HTTP = 4;
|
||||
DomainSocket = 5;
|
||||
}
|
||||
|
||||
message TransportConfig {
|
||||
|
17
transport/internet/domainsocket/config.go
Normal file
17
transport/internet/domainsocket/config.go
Normal file
@ -0,0 +1,17 @@
|
||||
package domainsocket
|
||||
|
||||
import "net"
|
||||
|
||||
func (c *Config) GetUnixAddr() (*net.UnixAddr, error) {
|
||||
path := c.Path
|
||||
if len(path) == 0 {
|
||||
return nil, newError("empty domain socket path")
|
||||
}
|
||||
if c.Abstract && path[0] != '\x00' {
|
||||
path = "\x00" + path
|
||||
}
|
||||
return &net.UnixAddr{
|
||||
Name: path,
|
||||
Net: "unix",
|
||||
}, nil
|
||||
}
|
@ -15,114 +15,35 @@ var _ = math.Inf
|
||||
// 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,
|
||||
type Config struct {
|
||||
// Path of the domain socket. This overrides the IP/Port parameter from upstream caller.
|
||||
Path string `protobuf:"bytes,1,opt,name=path" json:"path,omitempty"`
|
||||
// Abstract speicifies whether to use abstract namespace or not.
|
||||
// Traditionally Unix domain socket is file system based. Abstract domain socket can be used without acquiring file lock.
|
||||
Abstract bool `protobuf:"varint,2,opt,name=abstract" json:"abstract,omitempty"`
|
||||
}
|
||||
|
||||
func (x DomainSocketSecurityMode) String() string {
|
||||
return proto.EnumName(DomainSocketSecurityMode_name, int32(x))
|
||||
}
|
||||
func (DomainSocketSecurityMode) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||
func (m *Config) Reset() { *m = Config{} }
|
||||
func (m *Config) String() string { return proto.CompactTextString(m) }
|
||||
func (*Config) ProtoMessage() {}
|
||||
func (*Config) Descriptor() ([]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 {
|
||||
func (m *Config) GetPath() string {
|
||||
if m != nil {
|
||||
return m.Path
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *DomainSocketSettings) GetSecurity() *DomainSocketSecurity {
|
||||
func (m *Config) GetAbstract() bool {
|
||||
if m != nil {
|
||||
return m.Security
|
||||
return m.Abstract
|
||||
}
|
||||
return nil
|
||||
return false
|
||||
}
|
||||
|
||||
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)
|
||||
proto.RegisterType((*Config)(nil), "v2ray.core.transport.internet.domainsocket.Config")
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -130,26 +51,17 @@ func init() {
|
||||
}
|
||||
|
||||
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, 0x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xaa, 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,
|
||||
// 189 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xb2, 0x2e, 0x33, 0x2a, 0x4a,
|
||||
0xac, 0xd4, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x29, 0x4a, 0xcc, 0x2b,
|
||||
0x2e, 0xc8, 0x2f, 0x2a, 0xd1, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b, 0x2d, 0xd1, 0x4f, 0xc9,
|
||||
0xcf, 0x4d, 0xcc, 0xcc, 0x2b, 0xce, 0x4f, 0xce, 0x4e, 0x2d, 0xd1, 0x4f, 0xce, 0xcf, 0x4b, 0xcb,
|
||||
0x4c, 0xd7, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xd2, 0x82, 0x69, 0x2e, 0x4a, 0xd5, 0x83, 0x6b,
|
||||
0xd4, 0x83, 0x69, 0xd4, 0x43, 0xd6, 0xa8, 0x64, 0xc1, 0xc5, 0xe6, 0x0c, 0xd6, 0x2b, 0x24, 0xc4,
|
||||
0xc5, 0x52, 0x90, 0x58, 0x92, 0x21, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0x19, 0x04, 0x66, 0x0b, 0x49,
|
||||
0x71, 0x71, 0x24, 0x26, 0x15, 0x97, 0x14, 0x25, 0x26, 0x97, 0x48, 0x30, 0x29, 0x30, 0x6a, 0x70,
|
||||
0x04, 0xc1, 0xf9, 0x4e, 0xb9, 0x5c, 0x20, 0xe7, 0xe9, 0x11, 0x6f, 0x57, 0x00, 0x63, 0x14, 0x0f,
|
||||
0x32, 0x7f, 0x15, 0x93, 0x56, 0x98, 0x51, 0x50, 0x62, 0xa5, 0x9e, 0x33, 0x48, 0x73, 0x08, 0x5c,
|
||||
0xb3, 0x27, 0x4c, 0xb3, 0x0b, 0x58, 0x71, 0x30, 0x58, 0x71, 0x12, 0x1b, 0xd8, 0x6f, 0xc6, 0x80,
|
||||
0x00, 0x00, 0x00, 0xff, 0xff, 0xb8, 0xb3, 0xe6, 0x90, 0x1a, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
@ -1,42 +1,15 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package v2ray.core.internet.domainsocket;
|
||||
|
||||
package v2ray.core.transport.internet.domainsocket;
|
||||
option csharp_namespace = "V2Ray.Core.Transport.Internet.DomainSocket";
|
||||
option go_package = "domainsocket";
|
||||
option java_package = "com.v2ray.core.transport.internet.domainsocket";
|
||||
option java_multiple_files = true;
|
||||
|
||||
//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;
|
||||
message Config {
|
||||
// Path of the domain socket. This overrides the IP/Port parameter from upstream caller.
|
||||
string path = 1;
|
||||
// Abstract speicifies whether to use abstract namespace or not.
|
||||
// Traditionally Unix domain socket is file system based. Abstract domain socket can be used without acquiring file lock.
|
||||
bool abstract = 2;
|
||||
}
|
||||
|
@ -2,17 +2,44 @@ package domainsocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/tls"
|
||||
)
|
||||
|
||||
func DialDS(ctx context.Context, path string) (*net.UnixConn, error) {
|
||||
resolvedAddress, err := net.ResolveUnixAddr("unix", path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func getSettingsFromContext(ctx context.Context) *Config {
|
||||
rawSettings := internet.TransportSettingsFromContext(ctx)
|
||||
if rawSettings == nil {
|
||||
return nil
|
||||
}
|
||||
dialedUnix, err := net.DialUnix("unix", nil, resolvedAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dialedUnix, nil
|
||||
return rawSettings.(*Config)
|
||||
}
|
||||
|
||||
func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error) {
|
||||
settings := getSettingsFromContext(ctx)
|
||||
if settings == nil {
|
||||
return nil, newError("domain socket settings is not specified.").AtError()
|
||||
}
|
||||
|
||||
addr, err := settings.GetUnixAddr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn, err := net.DialUnix("unix", nil, addr)
|
||||
if err != nil {
|
||||
return nil, newError("failed to dial unix: ", settings.Path).Base(err).AtWarning()
|
||||
}
|
||||
|
||||
if config := tls.ConfigFromContext(ctx); config != nil {
|
||||
return tls.Client(conn, config.GetTLSConfig(tls.WithDestination(dest))), nil
|
||||
}
|
||||
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(internet.RegisterTransportDialer(internet.TransportProtocol_DomainSocket, Dial))
|
||||
}
|
||||
|
@ -2,216 +2,121 @@ package domainsocket
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
gotls "crypto/tls"
|
||||
"os"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/common/bitmask"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
"v2ray.com/core/transport/internet/tls"
|
||||
)
|
||||
|
||||
type Listener struct {
|
||||
ln net.Listener
|
||||
listenerChan chan<- net.Conn
|
||||
ctx context.Context
|
||||
path string
|
||||
lockfile *os.File
|
||||
state bitmask.Byte
|
||||
cancal func()
|
||||
addr *net.UnixAddr
|
||||
ln net.Listener
|
||||
tlsConfig *gotls.Config
|
||||
config *Config
|
||||
addConn internet.ConnHandler
|
||||
locker *fileLocker
|
||||
}
|
||||
|
||||
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
|
||||
func Listen(ctx context.Context, address net.Address, port net.Port, handler internet.ConnHandler) (internet.Listener, error) {
|
||||
settings := getSettingsFromContext(ctx)
|
||||
if settings == nil {
|
||||
return nil, newError("domain socket settings not specified.")
|
||||
}
|
||||
|
||||
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
|
||||
addr, err := settings.GetUnixAddr()
|
||||
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
|
||||
|
||||
unixListener, err := net.ListenUnix("unix", addr)
|
||||
if err != nil {
|
||||
return nil, newError("failed to listen domain socket").Base(err).AtWarning()
|
||||
}
|
||||
|
||||
ln := &Listener{
|
||||
addr: addr,
|
||||
ln: unixListener,
|
||||
config: settings,
|
||||
addConn: handler,
|
||||
}
|
||||
|
||||
if !settings.Abstract {
|
||||
ln.locker = &fileLocker{
|
||||
path: settings.Path + ".lock",
|
||||
}
|
||||
if err := ln.locker.Acquire(); err != nil {
|
||||
unixListener.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if config := tls.ConfigFromContext(ctx); config != nil {
|
||||
ln.tlsConfig = config.GetTLSConfig()
|
||||
}
|
||||
|
||||
go ln.run()
|
||||
|
||||
return ln, nil
|
||||
}
|
||||
|
||||
func giveupLock(locker *os.File) error {
|
||||
err := syscall.Flock(int(locker.Fd()), syscall.LOCK_UN)
|
||||
if err != nil {
|
||||
closeerr := locker.Close()
|
||||
func (ln *Listener) Addr() net.Addr {
|
||||
return ln.addr
|
||||
}
|
||||
|
||||
func (ln *Listener) Close() error {
|
||||
ln.locker.Release()
|
||||
return ln.ln.Close()
|
||||
}
|
||||
|
||||
func (ln *Listener) run() {
|
||||
for {
|
||||
conn, err := ln.ln.Accept()
|
||||
if err != nil {
|
||||
if ___DEBUG_PANIC_WHEN_ERROR_UNPROPAGATEABLE {
|
||||
panic(closeerr)
|
||||
if strings.Contains(err.Error(), "closed") {
|
||||
break
|
||||
}
|
||||
newError(closeerr).AtDebug().WriteToLog()
|
||||
newError("failed to accepted raw connections").Base(err).AtWarning().WriteToLog()
|
||||
continue
|
||||
}
|
||||
newError(err).AtDebug().WriteToLog()
|
||||
|
||||
if ln.tlsConfig != nil {
|
||||
conn = tls.Server(conn, ln.tlsConfig)
|
||||
}
|
||||
|
||||
ln.addConn(internet.Connection(conn))
|
||||
}
|
||||
}
|
||||
|
||||
type fileLocker struct {
|
||||
path string
|
||||
file *os.File
|
||||
}
|
||||
|
||||
func (fl *fileLocker) Acquire() error {
|
||||
f, err := os.Create(fl.path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
closeerr := locker.Close()
|
||||
if closeerr != nil {
|
||||
newError(closeerr).AtDebug().WriteToLog()
|
||||
return closeerr
|
||||
if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX); err != nil {
|
||||
f.Close()
|
||||
return newError("failed to lock file: ", fl.path).Base(err)
|
||||
}
|
||||
return closeerr
|
||||
fl.file = f
|
||||
return nil
|
||||
}
|
||||
|
||||
func cleansePath(path string) error {
|
||||
_, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
func (fl *fileLocker) Release() {
|
||||
if err := syscall.Flock(int(fl.file.Fd()), syscall.LOCK_UN); err != nil {
|
||||
newError("failed to unlock file: ", fl.path).Base(err).WriteToLog()
|
||||
}
|
||||
if err := fl.file.Close(); err != nil {
|
||||
newError("failed to close file: ", fl.path).Base(err).WriteToLog()
|
||||
}
|
||||
if err := os.Remove(fl.path); err != nil {
|
||||
newError("failed to remove file: ", fl.path).Base(err).WriteToLog()
|
||||
}
|
||||
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
|
||||
|
@ -2,131 +2,80 @@ package domainsocket_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"v2ray.com/core/transport/internet/domainsocket"
|
||||
"v2ray.com/ext/assert"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
. "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()
|
||||
assert := With(t)
|
||||
|
||||
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{
|
||||
Path: "/tmp/ts3",
|
||||
})
|
||||
listener, err := Listen(ctx, nil, net.Port(0), func(conn internet.Connection) {
|
||||
defer conn.Close()
|
||||
|
||||
b := buf.New()
|
||||
common.Must(b.Reset(buf.ReadFrom(conn)))
|
||||
assert(b.String(), Equals, "Request")
|
||||
|
||||
common.Must2(conn.Write([]byte("Response")))
|
||||
})
|
||||
assert(err, IsNil)
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := Dial(ctx, net.Destination{})
|
||||
assert(err, IsNil)
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte("Request"))
|
||||
assert(err, IsNil)
|
||||
|
||||
b := buf.New()
|
||||
common.Must(b.Reset(buf.ReadFrom(conn)))
|
||||
|
||||
assert(b.String(), Equals, "Response")
|
||||
}
|
||||
|
||||
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 TestListenAbstract(t *testing.T) {
|
||||
if runtime.GOOS != "linux" {
|
||||
return
|
||||
}
|
||||
|
||||
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()
|
||||
assert := With(t)
|
||||
|
||||
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{
|
||||
Path: "/tmp/ts3",
|
||||
Abstract: true,
|
||||
})
|
||||
listener, err := Listen(ctx, nil, net.Port(0), func(conn internet.Connection) {
|
||||
defer conn.Close()
|
||||
|
||||
b := buf.New()
|
||||
common.Must(b.Reset(buf.ReadFrom(conn)))
|
||||
assert(b.String(), Equals, "Request")
|
||||
|
||||
common.Must2(conn.Write([]byte("Response")))
|
||||
})
|
||||
assert(err, IsNil)
|
||||
defer listener.Close()
|
||||
|
||||
conn, err := Dial(ctx, net.Destination{})
|
||||
assert(err, IsNil)
|
||||
defer conn.Close()
|
||||
|
||||
_, err = conn.Write([]byte("Request"))
|
||||
assert(err, IsNil)
|
||||
|
||||
b := buf.New()
|
||||
common.Must(b.Reset(buf.ReadFrom(conn)))
|
||||
|
||||
assert(b.String(), Equals, "Response")
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, handler
|
||||
return nil, err
|
||||
}
|
||||
newError("listening TCP on ", address, ":", port).WithContext(ctx).WriteToLog()
|
||||
networkSettings := internet.TransportSettingsFromContext(ctx)
|
||||
tcpSettings := networkSettings.(*Config)
|
||||
|
||||
tcpSettings := getTCPSettingsFromContext(ctx)
|
||||
|
||||
l := &Listener{
|
||||
listener: listener,
|
||||
|
Loading…
Reference in New Issue
Block a user