From 37096b7d5bc437b87b6c8e2c1d2264e2e107c382 Mon Sep 17 00:00:00 2001 From: Vigilans Date: Thu, 9 Sep 2021 19:05:11 +0800 Subject: [PATCH 1/2] Change `SocketConfig.Mark` from int32 to uint32 --- common/session/session.go | 2 +- infra/conf/transport_internet.go | 2 +- transport/internet/config.pb.go | 8 ++++---- transport/internet/config.proto | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/session/session.go b/common/session/session.go index 2ee5cc46e10..dd41c914544 100644 --- a/common/session/session.go +++ b/common/session/session.go @@ -75,7 +75,7 @@ type Content struct { // Sockopt is the settings for socket connection. type Sockopt struct { // Mark of the socket connection. - Mark int32 + Mark uint32 } // SetAttribute attachs additional string attributes to content. diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index de547090062..26b03c03035 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -385,7 +385,7 @@ func (p TransportProtocol) Build() (string, error) { } type SocketConfig struct { - Mark int32 `json:"mark"` + Mark uint32 `json:"mark"` TFO *bool `json:"tcpFastOpen"` TProxy string `json:"tproxy"` AcceptProxyProtocol bool `json:"acceptProxyProtocol"` diff --git a/transport/internet/config.pb.go b/transport/internet/config.pb.go index c64f2d6455a..0a87a9e89e3 100644 --- a/transport/internet/config.pb.go +++ b/transport/internet/config.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.1 -// protoc v3.17.3 +// protoc v3.18.0--rc2 // source: transport/internet/config.proto package internet @@ -409,7 +409,7 @@ type SocketConfig struct { unknownFields protoimpl.UnknownFields // 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 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. @@ -455,7 +455,7 @@ func (*SocketConfig) Descriptor() ([]byte, []int) { return file_transport_internet_config_proto_rawDescGZIP(), []int{3} } -func (x *SocketConfig) GetMark() int32 { +func (x *SocketConfig) GetMark() uint32 { if x != nil { 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, 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, - 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, 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, diff --git a/transport/internet/config.proto b/transport/internet/config.proto index bbd834f1ce9..7aa76b6f2bb 100644 --- a/transport/internet/config.proto +++ b/transport/internet/config.proto @@ -56,7 +56,7 @@ message ProxyConfig { // SocketConfig is options to be applied on network sockets. message SocketConfig { // Mark of the connection. If non-zero, the value will be set to SO_MARK. - int32 mark = 1; + uint32 mark = 1; enum TCPFastOpenState { // AsIs is to leave the current TFO state as is, unmodified. From 28b33d04fc1c4a2140d43319710804983b2171be Mon Sep 17 00:00:00 2001 From: Vigilans Date: Thu, 9 Sep 2021 19:06:43 +0800 Subject: [PATCH 2/2] Make HTTP dialer accept socket config --- transport/internet/http/dialer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/transport/internet/http/dialer.go b/transport/internet/http/dialer.go index faf811b29ec..364db37e404 100644 --- a/transport/internet/http/dialer.go +++ b/transport/internet/http/dialer.go @@ -28,7 +28,7 @@ var ( 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() defer globalDialerAccess.Unlock() @@ -62,7 +62,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C address := net.ParseAddress(rawHost) 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 { return nil, err } @@ -100,7 +100,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me if tlsConfig == nil { 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) preader, pwriter := pipe.New(opts...)