1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

Use 'h2' for ALPN in TCP

This commit is contained in:
Darien Raymond 2018-01-02 18:16:36 +01:00
parent 27a63656ac
commit 30f27706e0
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 44 additions and 19 deletions

View File

@ -26,7 +26,7 @@ func Dial(ctx context.Context, dest net.Destination) (internet.Connection, error
return nil, err return nil, err
} }
if config := tls.ConfigFromContext(ctx, tls.WithDestination(dest)); config != nil { if config := tls.ConfigFromContext(ctx, tls.WithDestination(dest), tls.WithNextProto("h2")); config != nil {
conn = tls.Client(conn, config.GetTLSConfig()) conn = tls.Client(conn, config.GetTLSConfig())
} }

View File

@ -37,7 +37,7 @@ func ListenTCP(ctx context.Context, address net.Address, port net.Port, addConn
addConn: addConn, addConn: addConn,
} }
if config := tls.ConfigFromContext(ctx); config != nil { if config := tls.ConfigFromContext(ctx, tls.WithNextProto("h2")); config != nil {
l.tlsConfig = config.GetTLSConfig() l.tlsConfig = config.GetTLSConfig()
} }

View File

@ -40,6 +40,9 @@ func (c *Config) GetTLSConfig() *tls.Config {
if len(c.ServerName) > 0 { if len(c.ServerName) > 0 {
config.ServerName = c.ServerName config.ServerName = c.ServerName
} }
if len(c.NextProtocol) > 0 {
config.NextProtos = c.NextProtocol
}
return config return config
} }
@ -54,6 +57,14 @@ func WithDestination(dest net.Destination) Option {
} }
} }
func WithNextProto(protocol ...string) Option {
return func(config *Config) {
if len(config.NextProtocol) == 0 {
config.NextProtocol = protocol
}
}
}
func ConfigFromContext(ctx context.Context, opts ...Option) *Config { func ConfigFromContext(ctx context.Context, opts ...Option) *Config {
securitySettings := internet.SecuritySettingsFromContext(ctx) securitySettings := internet.SecuritySettingsFromContext(ctx)
if securitySettings == nil { if securitySettings == nil {

View File

@ -48,6 +48,8 @@ type Config struct {
Certificate []*Certificate `protobuf:"bytes,2,rep,name=certificate" json:"certificate,omitempty"` Certificate []*Certificate `protobuf:"bytes,2,rep,name=certificate" json:"certificate,omitempty"`
// Override server name. // Override server name.
ServerName string `protobuf:"bytes,3,opt,name=server_name,json=serverName" json:"server_name,omitempty"` ServerName string `protobuf:"bytes,3,opt,name=server_name,json=serverName" json:"server_name,omitempty"`
// Lists of string as ALPN values.
NextProtocol []string `protobuf:"bytes,4,rep,name=next_protocol,json=nextProtocol" json:"next_protocol,omitempty"`
} }
func (m *Config) Reset() { *m = Config{} } func (m *Config) Reset() { *m = Config{} }
@ -76,6 +78,13 @@ func (m *Config) GetServerName() string {
return "" return ""
} }
func (m *Config) GetNextProtocol() []string {
if m != nil {
return m.NextProtocol
}
return nil
}
func init() { func init() {
proto.RegisterType((*Certificate)(nil), "v2ray.core.transport.internet.tls.Certificate") proto.RegisterType((*Certificate)(nil), "v2ray.core.transport.internet.tls.Certificate")
proto.RegisterType((*Config)(nil), "v2ray.core.transport.internet.tls.Config") proto.RegisterType((*Config)(nil), "v2ray.core.transport.internet.tls.Config")
@ -84,21 +93,23 @@ func init() {
func init() { proto.RegisterFile("v2ray.com/core/transport/internet/tls/config.proto", fileDescriptor0) } func init() { proto.RegisterFile("v2ray.com/core/transport/internet/tls/config.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{ var fileDescriptor0 = []byte{
// 255 bytes of a gzipped FileDescriptorProto // 278 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0x41, 0x4b, 0x03, 0x31, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x90, 0x41, 0x6a, 0xeb, 0x30,
0x10, 0x85, 0x49, 0x17, 0x8a, 0x66, 0x55, 0x24, 0xa7, 0xbd, 0xb9, 0x2d, 0x14, 0xf6, 0x94, 0xc0, 0x10, 0x86, 0x71, 0xfc, 0x08, 0x2f, 0x72, 0x52, 0x8a, 0x56, 0xde, 0xd5, 0x49, 0x09, 0x78, 0x25,
0xfa, 0x0b, 0x74, 0x4f, 0x45, 0x90, 0x12, 0x8a, 0x07, 0x2f, 0x25, 0x86, 0xa9, 0x04, 0xb2, 0x49, 0x83, 0x7b, 0x82, 0xd6, 0xab, 0x50, 0x28, 0x46, 0x84, 0x2e, 0xba, 0x31, 0xaa, 0x98, 0x14, 0x83,
0x99, 0x8c, 0x95, 0xfd, 0x3b, 0x1e, 0xfd, 0x95, 0xd2, 0xad, 0x5b, 0xb6, 0xa7, 0xde, 0x92, 0x37, 0x2c, 0x85, 0xd1, 0x34, 0xad, 0xaf, 0xd4, 0x8b, 0xf4, 0x5a, 0xc5, 0x4e, 0x1c, 0x9c, 0x55, 0x76,
0xdf, 0xbc, 0xf7, 0x18, 0x5e, 0xef, 0x6b, 0x34, 0x9d, 0xb4, 0xb1, 0x55, 0x36, 0x22, 0x28, 0x42, 0xd2, 0xa7, 0x4f, 0xf3, 0xff, 0x0c, 0xcb, 0x0f, 0x39, 0xaa, 0x56, 0x68, 0xd7, 0x64, 0xda, 0x21,
0x13, 0xd2, 0x2e, 0x22, 0x29, 0x17, 0x08, 0x30, 0x00, 0x29, 0xf2, 0x49, 0xd9, 0x18, 0xb6, 0xee, 0x64, 0x84, 0xca, 0xfa, 0xbd, 0x43, 0xca, 0x6a, 0x4b, 0x80, 0x16, 0x28, 0x23, 0xe3, 0x33, 0xed,
0x53, 0xee, 0x30, 0x52, 0x14, 0xb3, 0x61, 0x07, 0x41, 0x9e, 0x78, 0x39, 0xf0, 0x92, 0x7c, 0x9a, 0xec, 0xae, 0xfe, 0x10, 0x7b, 0x74, 0xe4, 0xf8, 0x72, 0xf8, 0x83, 0x20, 0xce, 0xbe, 0x18, 0x7c,
0x3f, 0xf1, 0xbc, 0x01, 0x24, 0xb7, 0x75, 0xd6, 0x10, 0x88, 0xf2, 0xec, 0x5b, 0xb0, 0x92, 0x55, 0x41, 0xc6, 0xaf, 0x1e, 0x59, 0x54, 0x00, 0x52, 0xbd, 0xab, 0xb5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01, 0x7e, 0xcf, 0x16, 0x16, 0xbe, 0xa9, 0xea, 0x17, 0xa3, 0x9d, 0x89, 0xff, 0x25, 0x61,
0x36, 0x9d, 0x6c, 0x0e, 0xe8, 0xfa, 0x84, 0x2e, 0x07, 0x74, 0xed, 0xd3, 0xc7, 0xb4, 0xbf, 0xf2, 0x3a, 0x93, 0xf3, 0x0e, 0x96, 0x27, 0xf6, 0x24, 0xd9, 0x5a, 0xbb, 0xe6, 0x7a, 0x8f, 0x32, 0x78,
0xe3, 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x77, 0x0b, 0x8b, 0x74, 0x9b, 0x01, 0x00, 0x00, 0x0b, 0xc9, 0xf8, 0x9f, 0xc9, 0xf2, 0x35, 0x97, 0xaa, 0x15, 0x45, 0xa7, 0x6e, 0xcf, 0xea, 0x66,
0x50, 0xb7, 0xc6, 0xbf, 0x4f, 0xfb, 0xc4, 0x87, 0xbf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x3f, 0x84,
0xfb, 0x07, 0xc0, 0x01, 0x00, 0x00,
} }

View File

@ -23,4 +23,7 @@ message Config {
// Override server name. // Override server name.
string server_name = 3; string server_name = 3;
// Lists of string as ALPN values.
repeated string next_protocol = 4;
} }