Browse Source

:bug: http dialer add socket config; sockopt.mark use uint32 (#1264)

Ye Zhihao 4 years ago
parent
commit
4d155bc2bf

+ 1 - 1
common/session/session.go

@@ -75,7 +75,7 @@ type Content struct {
 // Sockopt is the settings for socket connection.
 // Sockopt is the settings for socket connection.
 type Sockopt struct {
 type Sockopt struct {
 	// Mark of the socket connection.
 	// Mark of the socket connection.
-	Mark int32
+	Mark uint32
 }
 }
 
 
 // SetAttribute attachs additional string attributes to content.
 // SetAttribute attachs additional string attributes to content.

+ 1 - 1
infra/conf/transport_internet.go

@@ -385,7 +385,7 @@ func (p TransportProtocol) Build() (string, error) {
 }
 }
 
 
 type SocketConfig struct {
 type SocketConfig struct {
-	Mark                 int32  `json:"mark"`
+	Mark                 uint32 `json:"mark"`
 	TFO                  *bool  `json:"tcpFastOpen"`
 	TFO                  *bool  `json:"tcpFastOpen"`
 	TProxy               string `json:"tproxy"`
 	TProxy               string `json:"tproxy"`
 	AcceptProxyProtocol  bool   `json:"acceptProxyProtocol"`
 	AcceptProxyProtocol  bool   `json:"acceptProxyProtocol"`

+ 4 - 4
transport/internet/config.pb.go

@@ -1,7 +1,7 @@
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // Code generated by protoc-gen-go. DO NOT EDIT.
 // versions:
 // versions:
 // 	protoc-gen-go v1.27.1
 // 	protoc-gen-go v1.27.1
-// 	protoc        v3.17.3
+// 	protoc        v3.18.0--rc2
 // source: transport/internet/config.proto
 // source: transport/internet/config.proto
 
 
 package internet
 package internet
@@ -409,7 +409,7 @@ type SocketConfig struct {
 	unknownFields protoimpl.UnknownFields
 	unknownFields protoimpl.UnknownFields
 
 
 	// Mark of the connection. If non-zero, the value will be set to SO_MARK.
 	// Mark of the connection. If non-zero, the value will be set to SO_MARK.
-	Mark int32 `protobuf:"varint,1,opt,name=mark,proto3" json:"mark,omitempty"`
+	Mark uint32 `protobuf:"varint,1,opt,name=mark,proto3" json:"mark,omitempty"`
 	// TFO is the state of TFO settings.
 	// TFO is the state of TFO settings.
 	Tfo SocketConfig_TCPFastOpenState `protobuf:"varint,2,opt,name=tfo,proto3,enum=v2ray.core.transport.internet.SocketConfig_TCPFastOpenState" json:"tfo,omitempty"`
 	Tfo SocketConfig_TCPFastOpenState `protobuf:"varint,2,opt,name=tfo,proto3,enum=v2ray.core.transport.internet.SocketConfig_TCPFastOpenState" json:"tfo,omitempty"`
 	// TProxy is for enabling TProxy socket option.
 	// TProxy is for enabling TProxy socket option.
@@ -455,7 +455,7 @@ func (*SocketConfig) Descriptor() ([]byte, []int) {
 	return file_transport_internet_config_proto_rawDescGZIP(), []int{3}
 	return file_transport_internet_config_proto_rawDescGZIP(), []int{3}
 }
 }
 
 
-func (x *SocketConfig) GetMark() int32 {
+func (x *SocketConfig) GetMark() uint32 {
 	if x != nil {
 	if x != nil {
 		return x.Mark
 		return x.Mark
 	}
 	}
@@ -567,7 +567,7 @@ var file_transport_internet_config_proto_rawDesc = []byte{
 	0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x13, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f,
 	0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x13, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f,
 	0x72, 0x74, 0x4c, 0x61, 0x79, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x22, 0x98, 0x04, 0x0a,
 	0x72, 0x74, 0x4c, 0x61, 0x79, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x78, 0x79, 0x22, 0x98, 0x04, 0x0a,
 	0x0c, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a,
 	0x0c, 0x53, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a,
-	0x04, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x6d, 0x61, 0x72,
+	0x04, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x6d, 0x61, 0x72,
 	0x6b, 0x12, 0x4e, 0x0a, 0x03, 0x74, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x3c,
 	0x6b, 0x12, 0x4e, 0x0a, 0x03, 0x74, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x3c,
 	0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e,
 	0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x74, 0x72, 0x61, 0x6e,
 	0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53,
 	0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53,

+ 1 - 1
transport/internet/config.proto

@@ -56,7 +56,7 @@ message ProxyConfig {
 // SocketConfig is options to be applied on network sockets.
 // SocketConfig is options to be applied on network sockets.
 message SocketConfig {
 message SocketConfig {
   // Mark of the connection. If non-zero, the value will be set to SO_MARK.
   // Mark of the connection. If non-zero, the value will be set to SO_MARK.
-  int32 mark = 1;
+  uint32 mark = 1;
 
 
   enum TCPFastOpenState {
   enum TCPFastOpenState {
     // AsIs is to leave the current TFO state as is, unmodified.
     // AsIs is to leave the current TFO state as is, unmodified.

+ 3 - 3
transport/internet/http/dialer.go

@@ -28,7 +28,7 @@ var (
 
 
 type dialerCanceller func()
 type dialerCanceller func()
 
 
-func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config) (*http.Client, dialerCanceller) {
+func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config, streamSettings *internet.MemoryStreamConfig) (*http.Client, dialerCanceller) {
 	globalDialerAccess.Lock()
 	globalDialerAccess.Lock()
 	defer globalDialerAccess.Unlock()
 	defer globalDialerAccess.Unlock()
 
 
@@ -62,7 +62,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C
 			address := net.ParseAddress(rawHost)
 			address := net.ParseAddress(rawHost)
 
 
 			detachedContext := core.ToBackgroundDetachedContext(ctx)
 			detachedContext := core.ToBackgroundDetachedContext(ctx)
-			pconn, err := internet.DialSystem(detachedContext, net.TCPDestination(address, port), nil)
+			pconn, err := internet.DialSystem(detachedContext, net.TCPDestination(address, port), streamSettings.SocketSettings)
 			if err != nil {
 			if err != nil {
 				return nil, err
 				return nil, err
 			}
 			}
@@ -100,7 +100,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
 	if tlsConfig == nil {
 	if tlsConfig == nil {
 		return nil, newError("TLS must be enabled for http transport.").AtWarning()
 		return nil, newError("TLS must be enabled for http transport.").AtWarning()
 	}
 	}
-	client, canceller := getHTTPClient(ctx, dest, tlsConfig)
+	client, canceller := getHTTPClient(ctx, dest, tlsConfig, streamSettings)
 
 
 	opts := pipe.OptionsFromContext(ctx)
 	opts := pipe.OptionsFromContext(ctx)
 	preader, pwriter := pipe.New(opts...)
 	preader, pwriter := pipe.New(opts...)