diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 11f77f99..efcb17ad 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - goVer: ['1.13', '1.17', '1.18'] + goVer: ['1.16', '1.17', '1.18'] steps: - uses: actions/checkout@v2 - name: Setup go ${{ matrix.goVer }} @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - goVer: ['1.13', '1.17', '1.18'] + goVer: ['1.16', '1.17', '1.18'] steps: - uses: actions/checkout@v2 - name: Setup go ${{ matrix.goVer }} @@ -59,7 +59,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - goVer: ['1.13', '1.17', '1.18'] + goVer: ['1.16', '1.17', '1.18'] steps: - uses: actions/checkout@v2 - name: Setup go ${{ matrix.goVer }} diff --git a/client_test.go b/client_test.go index c101a526..09ee80b9 100644 --- a/client_test.go +++ b/client_test.go @@ -65,7 +65,7 @@ func logoutAndClose(conn *connection, sessionID int64) { func TestConnection(t *testing.T) { hostAddress := HostAddress{Host: address, Port: port} conn := newConnection(hostAddress) - err := conn.open(hostAddress, testPoolConfig.TimeOut, nil) + err := conn.open(hostAddress, testPoolConfig.TimeOut, nil, false) if err != nil { t.Fatalf("fail to open connection, address: %s, port: %d, %s", address, port, err.Error()) } @@ -122,7 +122,7 @@ func TestConnection(t *testing.T) { func TestConnectionIPv6(t *testing.T) { hostAddress := HostAddress{Host: addressIPv6, Port: port} conn := newConnection(hostAddress) - err := conn.open(hostAddress, testPoolConfig.TimeOut, nil) + err := conn.open(hostAddress, testPoolConfig.TimeOut, nil, false) if err != nil { t.Fatalf("fail to open connection, address: %s, port: %d, %s", address, port, err.Error()) } @@ -254,7 +254,7 @@ func TestAuthentication(t *testing.T) { hostAddress := HostAddress{Host: address, Port: port} conn := newConnection(hostAddress) - err := conn.open(hostAddress, testPoolConfig.TimeOut, nil) + err := conn.open(hostAddress, testPoolConfig.TimeOut, nil, false) if err != nil { t.Fatalf("fail to open connection, address: %s, port: %d, %s", address, port, err.Error()) } @@ -1425,7 +1425,7 @@ func prepareSpace(spaceName string) error { conn := newConnection(hostAddress) testPoolConfig := GetDefaultConf() - err := conn.open(hostAddress, testPoolConfig.TimeOut, nil) + err := conn.open(hostAddress, testPoolConfig.TimeOut, nil, false) if err != nil { return fmt.Errorf("fail to open connection, address: %s, port: %d, %s", address, port, err.Error()) } @@ -1462,7 +1462,7 @@ func dropSpace(spaceName string) error { conn := newConnection(hostAddress) testPoolConfig := GetDefaultConf() - err := conn.open(hostAddress, testPoolConfig.TimeOut, nil) + err := conn.open(hostAddress, testPoolConfig.TimeOut, nil, false) if err != nil { return fmt.Errorf("fail to open connection, address: %s, port: %d, %s", address, port, err.Error()) } diff --git a/configs.go b/configs.go index e6e16ba0..01a188b5 100644 --- a/configs.go +++ b/configs.go @@ -29,6 +29,8 @@ type PoolConfig struct { MaxConnPoolSize int // The min connections in pool for all addresses MinConnPoolSize int + // UseHTTP2 indicates whether to use HTTP2 + UseHTTP2 bool } // validateConf validates config @@ -58,6 +60,7 @@ func GetDefaultConf() PoolConfig { IdleTime: 0 * time.Millisecond, MaxConnPoolSize: 10, MinConnPoolSize: 0, + UseHTTP2: false, } } @@ -128,6 +131,8 @@ type SessionPoolConf struct { maxSize int // The min sessions in pool for all addresses minSize int + // useHTTP2 indicates whether to use HTTP2 + useHTTP2 bool } type SessionPoolConfOption func(*SessionPoolConf) @@ -192,6 +197,12 @@ func WithMinSize(minSize int) SessionPoolConfOption { } } +func WithHTTP2(useHTTP2 bool) SessionPoolConfOption { + return func(conf *SessionPoolConf) { + conf.useHTTP2 = useHTTP2 + } +} + func (conf *SessionPoolConf) checkMandatoryFields() error { // Check mandatory fields if conf.username == "" { diff --git a/connection.go b/connection.go index 2cf680d5..05052d57 100644 --- a/connection.go +++ b/connection.go @@ -9,15 +9,18 @@ package nebula_go import ( + "context" "crypto/tls" "fmt" "net" + "net/http" "strconv" "time" "github.com/facebook/fbthrift/thrift/lib/go/thrift" "github.com/vesoft-inc/nebula-go/v3/nebula" "github.com/vesoft-inc/nebula-go/v3/nebula/graph" + "golang.org/x/net/http2" ) type connection struct { @@ -25,6 +28,7 @@ type connection struct { timeout time.Duration returnedAt time.Time // the connection was created or returned. sslConfig *tls.Config + useHTTP2 bool graph *graph.GraphServiceClient } @@ -40,28 +44,64 @@ func newConnection(severAddress HostAddress) *connection { // open opens a transport for the connection // if sslConfig is not nil, an SSL transport will be created -func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslConfig *tls.Config) error { +func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslConfig *tls.Config, useHTTP2 bool) error { ip := hostAddress.Host port := hostAddress.Port newAdd := net.JoinHostPort(ip, strconv.Itoa(port)) cn.timeout = timeout - bufferSize := 128 << 10 - - var err error - var sock thrift.Transport - if sslConfig != nil { - sock, err = thrift.NewSSLSocketTimeout(newAdd, sslConfig, timeout) + cn.useHTTP2 = useHTTP2 + + var ( + err error + transport thrift.Transport + pf thrift.ProtocolFactory + ) + if useHTTP2 { + if sslConfig != nil { + transport, err = thrift.NewHTTPPostClientWithOptions("https://"+newAdd, thrift.HTTPClientOptions{ + Client: &http.Client{ + Transport: &http2.Transport{ + TLSClientConfig: sslConfig, + }, + }, + }) + } else { + transport, err = thrift.NewHTTPPostClientWithOptions("http://"+newAdd, thrift.HTTPClientOptions{ + Client: &http.Client{ + Transport: &http2.Transport{ + // So http2.Transport doesn't complain the URL scheme isn't 'https' + AllowHTTP: true, + // Pretend we are dialing a TLS endpoint. (Note, we ignore the passed tls.Config) + DialTLSContext: func(ctx context.Context, network, addr string, cfg *tls.Config) (net.Conn, error) { + _ = cfg + var d net.Dialer + return d.DialContext(ctx, network, addr) + }, + }, + }, + }) + } + if err != nil { + return fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) + } + pf = thrift.NewBinaryProtocolFactoryDefault() } else { - sock, err = thrift.NewSocket(thrift.SocketAddr(newAdd), thrift.SocketTimeout(timeout)) - } - if err != nil { - return fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) - } + bufferSize := 128 << 10 - // Set transport - bufferedTranFactory := thrift.NewBufferedTransportFactory(bufferSize) - transport := thrift.NewHeaderTransport(bufferedTranFactory.GetTransport(sock)) - pf := thrift.NewHeaderProtocolFactory() + var sock thrift.Transport + if sslConfig != nil { + sock, err = thrift.NewSSLSocketTimeout(newAdd, sslConfig, timeout) + } else { + sock, err = thrift.NewSocket(thrift.SocketAddr(newAdd), thrift.SocketTimeout(timeout)) + } + if err != nil { + return fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) + } + // Set transport + bufferedTranFactory := thrift.NewBufferedTransportFactory(bufferSize) + transport = thrift.NewHeaderTransport(bufferedTranFactory.GetTransport(sock)) + pf = thrift.NewHeaderProtocolFactory() + } cn.graph = graph.NewGraphServiceClientFactory(transport, pf) if err = cn.graph.Open(); err != nil { @@ -92,7 +132,7 @@ func (cn *connection) verifyClientVersion() error { // When the timeout occurs, the connection will be reopened to avoid the impact of the message. func (cn *connection) reopen() error { cn.close() - return cn.open(cn.severAddress, cn.timeout, cn.sslConfig) + return cn.open(cn.severAddress, cn.timeout, cn.sslConfig, cn.useHTTP2) } // Authenticate diff --git a/connection_pool.go b/connection_pool.go index e7c8260d..3950b2fa 100644 --- a/connection_pool.go +++ b/connection_pool.go @@ -70,7 +70,7 @@ func NewSslConnectionPool(addresses []HostAddress, conf PoolConfig, sslConfig *t // initPool initializes the connection pool func (pool *ConnectionPool) initPool() error { - if err := checkAddresses(pool.conf.TimeOut, pool.addresses, pool.sslConfig); err != nil { + if err := checkAddresses(pool.conf.TimeOut, pool.addresses, pool.sslConfig, pool.conf.UseHTTP2); err != nil { return fmt.Errorf("failed to open connection, error: %s ", err.Error()) } @@ -79,7 +79,7 @@ func (pool *ConnectionPool) initPool() error { newConn := newConnection(pool.addresses[i%len(pool.addresses)]) // Open connection to host - if err := newConn.open(newConn.severAddress, pool.conf.TimeOut, pool.sslConfig); err != nil { + if err := newConn.open(newConn.severAddress, pool.conf.TimeOut, pool.sslConfig, pool.conf.UseHTTP2); err != nil { // If initialization failed, clean idle queue idleLen := pool.idleConnectionQueue.Len() for i := 0; i < idleLen; i++ { @@ -198,7 +198,7 @@ func (pool *ConnectionPool) releaseAndBack(conn *connection, pushBack bool) { // Ping checks availability of host func (pool *ConnectionPool) Ping(host HostAddress, timeout time.Duration) error { - return pingAddress(host, timeout, pool.sslConfig) + return pingAddress(host, timeout, pool.sslConfig, pool.conf.UseHTTP2) } // Close closes all connection @@ -249,7 +249,7 @@ func (pool *ConnectionPool) newConnToHost() (*connection, error) { host := pool.getHost() newConn := newConnection(host) // Open connection to host - if err := newConn.open(newConn.severAddress, pool.conf.TimeOut, pool.sslConfig); err != nil { + if err := newConn.open(newConn.severAddress, pool.conf.TimeOut, pool.sslConfig, pool.conf.UseHTTP2); err != nil { return nil, err } // Add connection to active queue @@ -356,23 +356,23 @@ func (pool *ConnectionPool) timeoutConnectionList() (closing []*connection) { // checkAddresses checks addresses availability // It opens a temporary connection to each address and closes it immediately. // If no error is returned, the addresses are available. -func checkAddresses(confTimeout time.Duration, addresses []HostAddress, sslConfig *tls.Config) error { +func checkAddresses(confTimeout time.Duration, addresses []HostAddress, sslConfig *tls.Config, useHTTP2 bool) error { var timeout = 3 * time.Second if confTimeout != 0 && confTimeout < timeout { timeout = confTimeout } for _, address := range addresses { - if err := pingAddress(address, timeout, sslConfig); err != nil { + if err := pingAddress(address, timeout, sslConfig, useHTTP2); err != nil { return err } } return nil } -func pingAddress(address HostAddress, timeout time.Duration, sslConfig *tls.Config) error { +func pingAddress(address HostAddress, timeout time.Duration, sslConfig *tls.Config, useHTTP2 bool) error { newConn := newConnection(address) // Open connection to host - if err := newConn.open(newConn.severAddress, timeout, sslConfig); err != nil { + if err := newConn.open(newConn.severAddress, timeout, sslConfig, useHTTP2); err != nil { return err } defer newConn.close() diff --git a/examples/basic_example/graph_client_basic_example.go b/examples/basic_example/graph_client_basic_example.go index 523a185e..976aefc3 100644 --- a/examples/basic_example/graph_client_basic_example.go +++ b/examples/basic_example/graph_client_basic_example.go @@ -21,6 +21,7 @@ const ( port = 3699 username = "root" password = "nebula" + useHTTP2 = false ) // Initialize logger @@ -31,6 +32,7 @@ func main() { hostList := []nebula.HostAddress{hostAddress} // Create configs for connection pool using default values testPoolConfig := nebula.GetDefaultConf() + testPoolConfig.UseHTTP2 = useHTTP2 // Initialize connection pool pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log) diff --git a/examples/goroutines_example/graph_client_goroutines_example.go b/examples/goroutines_example/graph_client_goroutines_example.go index edab10d4..0a919db9 100644 --- a/examples/goroutines_example/graph_client_goroutines_example.go +++ b/examples/goroutines_example/graph_client_goroutines_example.go @@ -24,6 +24,7 @@ const ( port = 3699 username = "root" password = "nebula" + useHTTP2 = false ) // Initialize logger @@ -34,6 +35,7 @@ func main() { hostList := []nebula.HostAddress{hostAddress} // Create configs for connection pool using default values testPoolConfig := nebula.GetDefaultConf() + testPoolConfig.UseHTTP2 = useHTTP2 // Initialize connection pool pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log) diff --git a/examples/json_example/parse_json_example.go b/examples/json_example/parse_json_example.go index 1a13ae72..54bf7cff 100644 --- a/examples/json_example/parse_json_example.go +++ b/examples/json_example/parse_json_example.go @@ -23,6 +23,7 @@ const ( port = 3699 username = "root" password = "nebula" + useHTTP2 = false ) // Initialize logger @@ -77,6 +78,7 @@ func main() { hostList := []nebula.HostAddress{hostAddress} // Create configs for connection pool using default values testPoolConfig := nebula.GetDefaultConf() + testPoolConfig.UseHTTP2 = useHTTP2 // Initialize connection pool pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log) diff --git a/examples/parameter_example/parameter_example.go b/examples/parameter_example/parameter_example.go index 07e3936e..028648db 100644 --- a/examples/parameter_example/parameter_example.go +++ b/examples/parameter_example/parameter_example.go @@ -21,6 +21,7 @@ const ( port = 3699 username = "root" password = "nebula" + useHTTP2 = false ) // Initialize logger @@ -31,6 +32,7 @@ func main() { hostList := []nebulago.HostAddress{hostAddress} // Create configs for connection pool using default values testPoolConfig := nebulago.GetDefaultConf() + testPoolConfig.UseHTTP2 = useHTTP2 // Initialize connection pool pool, err := nebulago.NewConnectionPool(hostList, testPoolConfig, log) diff --git a/examples/session_pool_example/session_pool_example.go b/examples/session_pool_example/session_pool_example.go index 53400240..108b10d1 100644 --- a/examples/session_pool_example/session_pool_example.go +++ b/examples/session_pool_example/session_pool_example.go @@ -24,6 +24,7 @@ const ( port = 3699 username = "root" password = "nebula" + useHTTP2 = false ) // Initialize logger @@ -39,6 +40,7 @@ func main() { "nebula", []nebula.HostAddress{hostAddress}, "example_space", + nebula.WithHTTP2(useHTTP2), ) if err != nil { log.Fatal(fmt.Sprintf("failed to create session pool config, %s", err.Error())) @@ -160,6 +162,7 @@ func prepareSpace() { hostList := []nebula.HostAddress{hostAddress} // Create configs for connection pool using default values testPoolConfig := nebula.GetDefaultConf() + testPoolConfig.UseHTTP2 = useHTTP2 // Initialize connection pool pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log) diff --git a/go.mod b/go.mod index d858ca15..94dca460 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,7 @@ go 1.13 require ( github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295 github.com/stretchr/testify v1.7.0 + golang.org/x/net v0.5.0 ) + +replace github.com/facebook/fbthrift => github.com/vesoft-inc/fbthrift v0.0.0-20230214024353-fa2f34755b28 diff --git a/go.sum b/go.sum index e449129e..ad317aca 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,43 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295 h1:ZA+qQ3d2In0RNzVpk+D/nq1sjDSv+s1Wy2zrAPQAmsg= -github.com/facebook/fbthrift v0.31.1-0.20211129061412-801ed7f9f295/go.mod h1:2tncLx5rmw69e5kMBv/yJneERbzrr1yr5fdlnTbu8lU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/vesoft-inc/fbthrift v0.0.0-20230201034936-5c5dd72a96c2 h1:6c6S8UfvfmwFGxnzeo9aieuZ/EQ0Z+8KfKJxx4sm61Y= +github.com/vesoft-inc/fbthrift v0.0.0-20230201034936-5c5dd72a96c2/go.mod h1:xu7e9za8StcJhBZmCDwK1Hyv4/Y0xFsjS+uqp10ECJg= +github.com/vesoft-inc/fbthrift v0.0.0-20230214024353-fa2f34755b28 h1:gpoPCGeOEuk/TnoY9nLVK1FoBM5ie7zY3BPVG8q43ME= +github.com/vesoft-inc/fbthrift v0.0.0-20230214024353-fa2f34755b28/go.mod h1:xu7e9za8StcJhBZmCDwK1Hyv4/Y0xFsjS+uqp10ECJg= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= +golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/session_pool.go b/session_pool.go index 0fef7358..75d7035c 100644 --- a/session_pool.go +++ b/session_pool.go @@ -10,7 +10,6 @@ package nebula_go import ( "container/list" - "crypto/tls" "fmt" "strconv" "sync" @@ -45,7 +44,6 @@ type SessionPool struct { closed bool cleanerChan chan struct{} //notify when pool is close rwLock sync.RWMutex - sslConfig *tls.Config } // NewSessionPool creates a new session pool with the given configs. @@ -72,7 +70,7 @@ func (pool *SessionPool) init() error { pool.rwLock.Lock() defer pool.rwLock.Unlock() // check the hosts status - if err := checkAddresses(pool.conf.timeOut, pool.conf.serviceAddrs, pool.sslConfig); err != nil { + if err := checkAddresses(pool.conf.timeOut, pool.conf.serviceAddrs, pool.conf.sslConfig, pool.conf.useHTTP2); err != nil { return fmt.Errorf("failed to initialize the session pool, %s", err.Error()) } @@ -306,12 +304,13 @@ func (pool *SessionPool) newSession() (*Session, error) { severAddress: graphAddr, timeout: 0 * time.Millisecond, returnedAt: time.Now(), - sslConfig: nil, + sslConfig: pool.conf.sslConfig, + useHTTP2: pool.conf.useHTTP2, graph: nil, } // open a new connection - if err := cn.open(cn.severAddress, pool.conf.timeOut, nil); err != nil { + if err := cn.open(cn.severAddress, pool.conf.timeOut, pool.conf.sslConfig, pool.conf.useHTTP2); err != nil { return nil, fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) }